Skip to content

Commit ec56026

Browse files
authored
Merge pull request #1 from pamelafox/perf_testing
Adding readme on how to run benchmarks
2 parents 46fb927 + 73987cf commit ec56026

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

tests/benchmarks/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
This folder contains benchmarks written using `pytest` and profiled using `pyinstrument`.
2+
3+
# Running the benchmarks
4+
5+
Open this repository in VSCode and wait for the devcontainer to start up.
6+
7+
Then you can run all the benchmarks with this command:
8+
9+
`python -m pytest tests/benchmarks`
10+
11+
Or use the keyword argument to run just one benchmark test:
12+
13+
`python -m pytest tests/benchmarks -k test_process_indexed_function`
14+
15+
When you run that test, a profile will also be saved in the `tests/benchmarks/.profiles` folder, in a file named after the profiled function. Open the file in a browser to see the profile.
16+
17+
If you run a benchmark test multiple times (either on same code or different versions of the code), you probably want to save it.
18+
19+
Either pass in `--benchmark-autosave` to save to an auto-generated filename or pass in `--benchmark-save=YOURNAME` to save with your specified name in the filename. All benchmark files will always start with a counter, beginning with 0001.
20+
21+
Once saved, compare using the `pytest-benchmark` command and the counter numbers:
22+
23+
`pytest-benchmark compare 0004 0005`
24+
25+
You can sort the comparison using `--sort`, save it to a CSV using `--csv`, or save it to a histogram with `--histogram`.
26+
More details available in the [pytest-benchmark reference](https://pytest-benchmark.readthedocs.io/en/latest/usage.html#comparison-cli).

0 commit comments

Comments
 (0)