CheckOps
pytest-benchmark
pytest-benchmark is a BSD-licensed pytest plugin providing a benchmark fixture that calibrates rounds automatically, compares runs and can fail tests on performance regressions.
Latest public signals
Not refreshed yet. Refresh reads the public site and, when the entry has a GitHub repository, the latest release.
Introduction
pytest-benchmark adds a benchmark fixture to pytest. The fixture is a callable that benchmarks any function passed to it, grouping the work into rounds calibrated to the timer’s precision, with sensible defaults for micro-benchmarks.
It integrates tightly with pytest, so you should know pytest basics first. It benchmarks functions only, can store results and compare against previous runs, and offers benchmark.pedantic for precise control over rounds, iterations and setup. Results can be exported as JSON for CI dashboards.
Whatever tool you choose, benchmark results are only useful if they are stable. Pin the hardware or runner, run enough iterations to make variance visible, and treat a single noisy result as a reason to rerun, not to block a merge.
The source code is at ionelmc/pytest-benchmark on GitHub under the BSD-2-Clause licence, with about 1,500 stars; the most recent commit was on 1 November 2026.
Features
- benchmark fixture: Benchmark any callable.
- Automatic calibration: Rounds sized to timer precision.
- Pedantic mode: Control rounds and setup.
- Comparisons: Compare saved runs.
- Regression failure: Fail on slowdowns.
- JSON export: For CI tools.
Pros
- Free to use: Open source under the BSD-2-Clause licence, so the core tool costs nothing to use.
- Actively maintained: The repository had commits as recent as 1 November 2026.
Cons
- Function-level only: Not for end-to-end timing.
- Noisy on shared CI: Needs stable runners.
Usage and Links (Example)
pip install pytest-benchmark
def test_my_stuff(benchmark):
result = benchmark(sum, range(1000))
assert result == 499500
pytest --benchmark-compare # compare with a previously saved run
Resources:
Pricing
pytest-benchmark is free and open source under the BSD-2-Clause licence.
Recommended for?
- Python developers adding performance checks to existing pytest suites.
Conclusion
pytest-benchmark is the easiest way to benchmark Python code.
Store baselines and compare on every change.
On CheckOps, pytest-benchmark is filed under the Performance & load and Unit testing stages. Related tools listed here include pytest, pytest-xdist, hyperfine, Locust, Coverage.py and Hypothesis. A short trial on a real project, with your own code, data and pipeline, is usually the fastest way to choose between them, because fit matters more than feature lists. Facts here come from the official site, documentation and repository, checked on 11 November 2026.
Alternatives
Other tools on CheckOps that cover similar ground. Open a page, or compare one with pytest-benchmark side by side.
- Ppytestpytest is the usual Python test runner: plain asserts, fixtures, parametrization, and a large plugin set.Compare with pytest-benchmark
Ppytest-xdistpytest-xdist is an MIT pytest plugin that distributes tests across multiple CPUs or machines, speeding up large Python suites with load balancing.Compare with pytest-benchmark
Hhyperfinehyperfine is an Apache-2.0 command-line benchmarking tool that runs shell commands repeatedly with warm-up, statistical analysis and exports, ideal for comparing CLIs and builds.Compare with pytest-benchmark- LLocustWrite scalable load tests in plain Python 🚗💨.Compare with pytest-benchmark
CCoverage.pyCoverage.py is the standard Apache-2.0 code coverage tool for Python, measuring line and branch coverage and producing terminal, HTML, XML, JSON and LCOV reports; pytest-cov builds on it.Compare with pytest-benchmark
HHypothesisHypothesis is the MPL-2.0 property-based testing library for Python: describe the range of inputs, let it generate cases including edge cases, and get the simplest failing example when a property breaks.Compare with pytest-benchmark