How to Benchmark Python Code?
codspeed.mintlify.devΒ·5dΒ·
Discuss: Hacker News
Flag this post

Choosing our Benchmarking Strategy

We are going to use pytest-codspeed because it integrates seamlessly with pytest, the most popular Python testing framework. Your benchmarks live right alongside your tests using the same familiar syntax, no separate infrastructure to maintain. Plus, all of pytest’s ecosystem (parametrization, fixtures, plugins) works seamlessly with your benchmarks. You can even turn existing tests into benchmarks by adding a single decorator.

Your First Benchmark

Let’s start by creating a simple benchmark for a recursive Fibonacci function.

Installation

First, add pytest-codspeed to your project’s dependencies using uv:

uv add --dev ...

Similar Posts

Loading similar posts...