docs | |
---|---|
tests | |
package |
A py.test
fixture for benchmarking code. It will group the tests into rounds that are calibrated to the chosen
timer. See calibration and FAQ.
- Free software: BSD license
pip install pytest-benchmark
pytest-benchmark.readthedocs.org
This plugin provides a benchmark fixture. This fixture is a callable object that will benchmark any function passed to it.
Example:
def something(duration=0.000001):
# Code to be measured
return time.sleep(duration)
def test_my_stuff(benchmark):
# benchmark something
result = benchmark(something)
# Extra code, to verify that the run completed correctly.
# Note: this code is not measured.
assert result is None
You can also pass extra arguments:
def test_my_stuff(benchmark):
result = benchmark(time.sleep, 0.02)
Normal run:
Compare mode (--benchmark-compare
):
Histogram (--benchmark-histogram
):
Also, it has nice tooltips.
To run the all tests run:
tox
- Timing code and ideas taken from: https://bitbucket.org/haypo/misc/src/tip/python/benchmark.py