Debian Codegraph @

benchmarks/README.md

raw
1 # Benchmarking
2
3 `Param` uses ASV (https://asv.readthedocs.io) for benchmarking.
4
5 ## Preparation
6
7 Install `asv` into your environment with for example:
8 ```
9 hatch shell
10 cd benchmarks
11 pip install asv
12 ```
13
14 ASV then runs benchmarks in isolated virtual environments that it creates using `virtualenv`.
15
16 ## Running benchmarks
17
18 To run all benchmarks against the default `main` branch:
19 ```
20 cd benchmarks
21 asv run
22 ```
23
24 The first time this is run it will create a machine file to store information about your machine. Then a virtual environment will be created and each benchmark will be run multiple times to obtain a statistically valid benchmark time.
25
26 To list the benchmark timings stored for the `main` branch use:
27 ```
28 asv show main
29 ```
30
31 ASV ships with its own simple webserver to interactively display the results in a webbrowser. To use this:
32 ```
33 asv publish
34 asv preview
35 ```
36 and then open a web browser at the URL specified.
37
38 If you want to quickly run all benchmarks once only to check for errors, etc, use:
39 ```
40 asv dev
41 ```
42 instead of `asv run`.
43
44
45 ## Adding new benchmarks
46
47 Add new benchmarks to existing or new classes in the `benchmarks/benchmarks` directory. Any class member function with a name that starts with `time` will be identified as a timing benchmark when `asv` is run.
48
49 Data that is required to run benchmarks is usually created in the `setup()` member function. This ensures that the time taken to setup the data is not included in the benchmark time. The `setup()` function is called once for each invocation of each benchmark, the data are not cached.
50
51 At the top of each benchmark class there are lists of parameter names and values. Each benchmark is repeated for each unique combination of these parameters.
52
53 If you only want to run a subset of benchmarks, use syntax like:
54 ```
55 asv run -b ShadeCategorical
56 ```
57 where the text after the `-b` flag is used as a regex to match benchmark file, class and function names.
58
59
60 ## Benchmarking code changes
61
62 You can compare the performance of code on different branches and in different commits. Usually if you want to determine how much faster a new algorithm is, the old code will be in the `main` branch and the new code will be in a new feature branch. Because ASV uses virtual environments and checks out the `param` source code into these virtual environments, your new code must be committed into the new feature branch locally.
63
64 To benchmark the latest commits on `main` and your new feature branch, edit `asv.conf.json` to change the line
65 ```
66 "branches": ["main"],
67 ```
68 into
69 ```
70 "branches": ["main", "new_feature_branch"],
71 ```
72 or similar.
73
74 Now when you `asv run` the benchmarks will be run against both branches in turn.
75
76 Then use
77 ```
78 asv show
79 ```
80 to list the commits that have been benchmarked, and
81 ```
82 asv compare commit1 commit2
83 ```
84 to give you a side-by-side comparison of the two commits.
85
86 You can run `asv` for single tags and compare them
87 ```
88 asv run v0.0.1^!
89 asv run v0.0.2^!
90 asv compare v0.0.1 v0.0.2
91 ```
92
93 ```
94 asv run v0.0.2..HEAD