A .NET library for turning C# methods into reproducible benchmarks, with automatic warm-up, statistics and result reports.
ionelmc/pytest-benchmark
A pytest plugin that provides a benchmark fixture for timing Python functions in pytest test suites.
- Stars
- 1,459
- Forks
- 139
- Open issues
- 125
- Last commit
- 6 days ago
What is it?
pytest-benchmark adds a benchmark fixture to pytest. Passing a function to the fixture runs it repeatedly, grouping runs into rounds calibrated to the chosen timer, and reports the timing results in pytest's summary output.
The fixture can be called with positional or keyword arguments, and a pedantic mode gives explicit control over setup functions, iteration counts and round counts. Results can be compared against earlier runs, and the plugin can generate histograms of the timing distribution.
Because it integrates with pytest, benchmarks are written as ordinary test functions and run with the usual pytest command. The plugin benchmarks single functions, so measuring a larger block of code requires wrapping it in a function.
Key features
- 01Provides a benchmark fixture that times a function call inside a pytest test.
- 02Groups measurements into calibrated rounds for the chosen timer.
- 03Offers a pedantic mode for custom setup, iterations and rounds.
- 04Supports comparing results against previous benchmark runs.
- 05Can generate histograms of timing results.
Use cases
- Tracking performance regressions of Python functions across commits.
- Comparing two implementations of the same function within a test suite.
- Measuring hot paths in a library while keeping benchmarks in the existing pytest workflow.
Quick start
- 1
Install the plugin from PyPI
pip install pytest-benchmark
Things to know
- It benchmarks only single functions, so whole programs or code blocks need a wrapper function.
Topics
FAQ
- What is pytest-benchmark?
- A pytest plugin that provides a benchmark fixture for timing Python functions in pytest test suites. pytest-benchmark adds a benchmark fixture to pytest. Passing a function to the fixture runs it repeatedly, grouping runs into rounds calibrated to the chosen timer, and reports the timing results in pytest's summary output.
- Is pytest-benchmark free to use? What license does it have?
- pytest-benchmark is open source under the BSD-2-Clause license. Check the license terms before using it in commercial products.
- Is pytest-benchmark still maintained?
- Actively maintained. The last commit to pytest-benchmark was on Nov 1, 2026.
- What can I use pytest-benchmark for?
- Tracking performance regressions of Python functions across commits. Comparing two implementations of the same function within a test suite. Measuring hot paths in a library while keeping benchmarks in the existing pytest workflow.
- How do I install pytest-benchmark?
- Install the plugin from PyPI: pip install pytest-benchmark
- Where can I get pytest-benchmark?
- The source code and installation instructions are on GitHub: https://github.com/ionelmc/pytest-benchmark
Summary generated by AI from the project's README. GitHub stats refresh daily.
Related projects
Line-by-line profiler for Python that shows how much time each source line of a decorated function takes.
Open-source Java application for load testing and measuring the performance of web applications and other services.
A cross-platform command-line HTTP(S) benchmarking and load-testing tool written in Go, built on fasthttp for high request throughput.
A command-line tool for benchmarking and load testing gRPC services, with configurable concurrency, rate limits and output formats.
Macrobenchmarking framework for Elasticsearch that sets up clusters, runs benchmark races, and compares results.