pytest-benchmark
testing
benchmarking
Links
pytest-benchmark
is a plugin for the pytest
testing framework that enables developers to measure and track the performance of their code. It provides a fixture to benchmark functions, offering features like automatic calibration, comparison and regression tracking, and detailed statistics. This tool is particularly useful for identifying performance bottlenecks and ensuring that code changes do not degrade performance.
oaicite:0
Usage Example
Here’s an example of how to use pytest-benchmark
to benchmark a function:
import time
def my_function():
time.sleep(0.1)
def test_my_function(benchmark):
benchmark(my_function)
In this example:
my_function
is a simple function that sleeps for 0.1 seconds.- The
test_my_function
function uses thebenchmark
fixture provided bypytest-benchmark
to measure the performance ofmy_function
.
To run the benchmark, execute:
pytest test_my_function.py
This will output performance metrics for my_function
, helping you assess its efficiency.
oaicite:1