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.
- --benchmark-max-time=BENCHMARK_MAX_TIME
Maximum time to spend in a benchmark.
- --benchmark-min-rounds=BENCHMARK_MIN_ROUNDS
Minimum rounds, even if total time would exceed –max-time.
- --benchmark-sort=BENCHMARK_SORT
Column to sort on. Can be one of: ‘min’, ‘max’, ‘mean’ or ‘stddev’ .
- --benchmark-timer=BENCHMARK_TIMER
Timer to use when measuring time.
- --benchmark-warmup
Runs the benchmarks two times. Discards data from the first run.
- --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.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
Hashes for pytest_benchmark-2.1.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1fb3055620e2140142fe8f60ebef5d7ccc8bc58a902d7f54572fb50af06b62c7 |
|
MD5 | ce201667f0f97483c213f00cedf490b3 |
|
BLAKE2b-256 | 0d772aac319bc15d530917641a2cbca9dc9dce2e257b534664729edfaed5e111 |