--- id: pytest-benchmark version: "5.2.3" license: BSD-2-Clause license_treatment: permissive maintenance: active --- # pytest-benchmark — A ``pytest`` fixture for benchmarking code. It will group the tests into rounds that are calibrated to the chosen timer. License: permissive · Maintenance: active · Downloads: 14.2M/mo ## What it is and what it does pytest-benchmark is a pytest plugin that turns test functions into performance benchmarks by wrapping code execution in a calibrated timing harness. It groups runs into rounds, automatically adjusting iteration counts to produce stable measurements, and generates comparison reports and histograms. The package integrates directly into pytest's test discovery and reporting, so you write benchmarks as normal test functions that receive a `benchmark` fixture. The plugin is designed for function-level micro-benchmarking and provides both simple mode (pass a function and arguments) and pedantic mode with explicit control over setup, iterations, rounds, and per-round teardown. It collects CPU info via py-cpuinfo and supports profiling, tracing, and cProfile integration. Results can be compared across runs and exported to CSV. Use it for: - Measure and track performance regressions in a CI/CD pipeline by comparing benchmark results across commits. - Profile and optimize hot-path functions by running repeated timed iterations with automatic calibration. - Generate performance reports and histograms to document the speed of critical algorithms or library functions. - Set up parametrized benchmarks to test performance across different input sizes or configurations. - Integrate cProfile or tracing into benchmarks to identify bottlenecks in slow functions. ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. A pytest fixture that benchmarks Python functions by running them in calibrated rounds and generating performance reports with timing statistics. Yes. pytest-benchmark is actively maintained, has no known vulnerabilities, low install friction, and a permissive license. It is the standard tool for pytest-based performance testing and is well-suited for any project that needs to track or optimize function-level performance. ## Install pip install pytest-benchmark uv add pytest-benchmark poetry add pytest-benchmark ## Installing pytest-benchmark Before you install: Low friction install with only two runtime dependencies (pytest and py-cpuinfo). Actively maintained with recent updates for pytest 9.0 compatibility. License in practice: BSD-2-Clause is a permissive license with minimal restrictions; you can use this package in commercial and proprietary projects with only attribution requirements. Quickstart: pip install pytest-benchmark import time def test_my_function(benchmark): def work(): time.sleep(0.000001) result = benchmark(work) assert result is None Requires Python 3.9 or later and pytest to be installed; benchmarks run via pytest command, not standalone. Verify before relying: - Exact overhead or accuracy impact of the calibration mechanism on very fast functions. - Whether py-cpuinfo is always required or only for CPU-specific timing modes. - Performance characteristics when benchmarking code blocks versus individual functions. ## Package facts - License: BSD-2-Clause (permissive) - Python support: supports_current - Install friction: low - Maintenance: active - Downloads: 14.2M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags pytest benchmarking fixture, performance testing python, code timing and profiling, benchmark test runner, function performance measurement, pytest performance plugin, timing calibration tool, performance-testing, pytest-plugin, profiling [View on SkillFed](https://skillfed.io/packages/pytest-benchmark) · [View on PyPI](https://pypi.org/project/pytest-benchmark/)