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):
with benchmark:
# Code to be measured
result = 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-max-time=BENCHMARK_MAX_TIME
Maximum time to spend in a benchmark (including overhead).
- --benchmark-max-iterations=BENCHMARK_MAX_ITERATIONS
Maximum iterations to do.
- --benchmark-min-iterations=BENCHMARK_MIN_ITERATIONS
Minium iterations, even if total time would exceed max-time.
- --benchmark-scale=BENCHMARK_SCALE
Minium iterations, even if total time would exceed max-time.
- --benchmark-timer=BENCHMARK_TIMER
Timer to use when measuring time.
- --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", max_time=0.5,
max_iterations=5000, min_iterations=5,
timer=time.time, disable_gc=True)
def test_my_stuff(benchmark):
with benchmark:
# Code to be measured
result = 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
Changelog
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
pytest-benchmark-1.0.0.tar.gz
(27.9 kB
view hashes)
Built Distribution
Close
Hashes for pytest_benchmark-1.0.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ebf4f514e9727fd0e5004e8998f630f38306ecb1536ae5fee2acef38e20cf1d |
|
MD5 | 969ef95a7e3ca1c80c12915e55ddc68e |
|
BLAKE2b-256 | a5189372c72896f7abd6200591a50ea2719f6019c381439d0a53010222f85ed2 |