py.test fixture for benchmarking code
Project description
A py.test fixture for benchmarking code.
Free software: BSD license
Installation
pip install pytest-benchmark
Usage
def test_my_stuff(benchmark):
@benchmark
def result():
# Code to be measured
return time.sleep(0.000001)
# Extra code, to verify that the run completed correctly.
# Note: this code is not measured.
assert result is None
py.test command-line options:
- --benchmark-min-time=BENCHMARK_MIN_TIME
Minimum time per round. Default: 25.00us
- --benchmark-max-time=BENCHMARK_MAX_TIME
Maximum time to spend in a benchmark. Default: 1.00s
- --benchmark-min-rounds=BENCHMARK_MIN_ROUNDS
Minimum rounds, even if total time would exceed –max-time. Default: 5
- --benchmark-sort=BENCHMARK_SORT
Column to sort on. Can be one of: ‘min’, ‘max’, ‘mean’ or ‘stddev’. Default: min
- --benchmark-timer=BENCHMARK_TIMER
Timer to use when measuring time. Default: time.perf_counter
- --benchmark-warmup
Runs the benchmarks two times. Discards data from the first run.
- --benchmark-warmup-iterations=BENCHMARK_WARMUP_ITERATIONS
Max number of iterations to run in the warmup phase. Default: 100000
- --benchmark-verbose
Dump diagnostic and progress information.
- --benchmark-disable-gc
Disable GC during benchmarks.
- --benchmark-skip
Skip running any benchmarks.
- --benchmark-only
Only run benchmarks.
Setting per-test options:
@pytest.mark.benchmark(
group="group-name",
min_time=0.1,
max_time=0.5,
min_rounds=5,
timer=time.time,
disable_gc=True,
warmup=False
)
def test_my_stuff(benchmark):
@benchmark
def result():
# Code to be measured
return time.sleep(0.000001)
# Extra code, to verify that the run
# completed correctly.
# Note: this code is not measured.
assert result is None
Documentation
Obligatory screenshot
Development
To run the all tests run:
tox
Credits
Timing code and ideas taken from: https://bitbucket.org/haypo/misc/src/tip/python/benchmark.py
Changelog
2.3.0 (2014-12-27)
Moved the warmup in the calibration phase. Solves issues with benchmarking on PyPy.
Added a --benchmark-warmup-iterations option to fine-tune that.
2.2.0 (2014-12-26)
Make the default rounds smaller (so that variance is more accurate).
Show the defaults in the --help section.
2.1.0 (2014-12-20)
Simplify the calibration code so that the round is smaller.
Add diagnostic output for calibration code (--benchmark-verbose).
2.0.0 (2014-12-19)
Replace the context-manager based API with a simple callback interface.
Implement timer calibration for precise measurements.
1.0.0 (2014-12-15)
Use a precise default timer for PyPy.
? (?)
Readme and styling fixes (contributed by Marc Abramowitz)
Lots of wild changes.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pytest-benchmark-2.3.0.tar.gz
.
File metadata
- Download URL: pytest-benchmark-2.3.0.tar.gz
- Upload date:
- Size: 36.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 94fb2b774f56243a06a97f9e5c38371cfe411361bddbcadb38bf7d4c378a20cf |
|
MD5 | 8b14c75a2b62fc82779b76786b5d5c40 |
|
BLAKE2b-256 | 8c41e81a3596d8962f089214d0f3afb06a6e4d0d9994bae5cdb6d285c572f1cf |
File details
Details for the file pytest_benchmark-2.3.0-py2.py3-none-any.whl
.
File metadata
- Download URL: pytest_benchmark-2.3.0-py2.py3-none-any.whl
- Upload date:
- Size: 17.8 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c1b8253e6ec8ec1bce9d37e60e4f1ddd790d26c7e5971abb6820637bb2155d6a |
|
MD5 | 4f400262464bdfa769b658dbd604339a |
|
BLAKE2b-256 | 653aa25b74ee6b5057f91ee84538aea5529a9b978be8beb421cf6d2d6fb14999 |