Skip to main content
CodSpeed is a performance testing tool helping you to consistently measure the performance of your codebase locally and in your CI/CD pipeline. More details on how CodSpeed works here: What is CodSpeed? This guide is a quick start to get a sample Python repository on GitHub up and running with CodSpeed:
  1. Create Performance Tests
  2. Connect your Repository
  3. Run the Tests in your CI
  4. Introduce a Performance Regression

Create Performance Tests

  1. Install the CodSpeed plugin for pytest:
    pip install pytest-codspeed
    
  2. Write a performance test using the @pytest.mark.benchmark marker:
    tests/test_sum_squares.py
    import pytest
    
    def sum_squares(arr):
        """Sum the squares of the numbers in an array."""
        total = 0
        for x in arr:
            total += x * x
        return total
    
    # Your tests can also be benchmarks
    @pytest.mark.benchmark
    def test_sum_squares():
        assert sum_squares(range(1000)) == 332833500
    
  3. Run your performance tests locally:
    $ pytest tests/ --codspeed
    ============================= test session starts ====================
    platform darwin -- Python 3.13.0, pytest-7.4.4, pluggy-1.5.0
    codspeed: 3.0.0 (enabled, mode: walltime, timer_resolution: 41.7ns)
    rootdir: /home/user/codspeed-test, configfile: pytest.ini
    plugins: codspeed-3.0.0
    collected 1 items
    
    tests/test_sum_squares.py .                                    [ 100%]
    
                             Benchmark Results
    ┏━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━┓
    ┃     Benchmark  ┃ Time (best) ┃ Rel. StdDev ┃ Run time ┃ Iters  ┃
    ┣━━━━━━━━━━━━━━━━╋━━━━━━━━━━━━━╋━━━━━━━━━━━━━╋━━━━━━━━━━╋━━━━━━━━┫
    ┃test_sum_squares┃     1,873ns ┃        4.8% ┃    3.00s ┃ 66,930 ┃
    ┗━━━━━━━━━━━━━━━━┻━━━━━━━━━━━━━┻━━━━━━━━━━━━━┻━━━━━━━━━━┻━━━━━━━━┛
    =============================== 1 benchmarked ========================
    =============================== 1 passed in 4.12s ====================
    
    Great! We set up our first performance test. Now, let’s track the performance in the CI with CodSpeed!

Connect your Repository

  1. Login on CodSpeed
  2. Go to settings and install the CodSpeed GitHub App by clicking on the “Import” button.