pyperf is a Python module designed to write, run, and analyze benchmarks. It provides a robust API for reliable performance measurements, including automatic calibration, multi-process execution, statistical analysis with outlier detection, and comprehensive metadata collection. Currently at version 2.10.0, pyperf maintains an active release cadence with regular updates and requires Python 3.9 or newer.
pip install pyperfVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates benchmarking a simple function using `pyperf.Runner`. It shows how to define a function to be benchmarked and then execute it with the runner. The output will include mean execution time and standard deviation. For more complex scenarios, `runner.timeit()` is suitable for benchmarking single statements, and results can be saved to a JSON file using the `-o` command-line option when running the script.
Upgrade your Python environment to 3.9 or newer. For Python 2.7, use `pyperf==1.7.1`.
Update all imports from `import perf` to `import pyperf` in your code.
Replace calls to `pyperf.perf_counter()` with `time.perf_counter()`.
Rerun the benchmark with more `--runs`, `--values`, or `--loops` (e.g., `python3 your_script.py --runs 40 --values 20`). Consider running `python3 -m pyperf system tune` to prepare your system for stable benchmarking.
Install the `psutil` dependency: `pip install psutil`.
Update your code and command-line scripts to use 'value' terminology. For instance, replace `runner.bench_sample_func()` with `runner.bench_time_func()`.
Update your import statements from `import perf` to `import pyperf`, and update any references to `perf` within your code.
Upgrade your Python environment to version 3.9 or higher. If you must use Python 2.7, install an older version of pyperf: `pip install pyperf==1.7.1`.
Increase the number of runs, values, and/or loops by passing options like `--runs N`, `--values N`, `--loops N` to your benchmark command. Running `python3 -m pyperf system tune` can also help reduce system jitter.
Update your code to use the newer method name: `runner.bench_time_func()`. Similarly, update any command-line options like `--samples` to `--values`.