> ## Documentation Index
> Fetch the complete documentation index at: https://codspeed.io/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Quickstart

> Get started with CodSpeed and performance testing in a few minutes

CodSpeed measures your code performance locally and in your CI/CD pipeline, so
you can catch regressions before they ship and optimize your critical code
paths. Learn more about [how CodSpeed works](https://codspeed.io/docs/what-is-codspeed.md).

This guide walks you through
[connecting your repository](#connect-your-repository) and then
[setting up CodSpeed](#setup).

## Connect your Repository

1. [Login on CodSpeed](https://app.codspeed.io/login)

2. Go to [settings](https://app.codspeed.io/settings) and install the CodSpeed
   GitHub App by clicking on the "Import" button.

   ![Adding a new repository from the settings page](https://mintcdn.com/codspeed/jKaxX6yy-Kzw1C-0/assets/add-new-repository.png?fit=max\&auto=format\&n=jKaxX6yy-Kzw1C-0\&q=85\&s=84fb767d81b990e9ba590bf2a8adc0c8)

3. Select the organization or the user and add the repositories you want to use
   with CodSpeed:

   ![Github App organization selection](https://mintcdn.com/codspeed/jKaxX6yy-Kzw1C-0/assets/select-organization.png?fit=max\&auto=format\&n=jKaxX6yy-Kzw1C-0\&q=85\&s=04ad62074c1d5b91f6f90748cf3067f2)

4. After connecting your repository, you can proceed to the [setup](#setup) to
   start tracking performance.

## Setup

In the [CodSpeed settings](https://app.codspeed.io/settings), configure a
repository by clicking on the "Setup" button:

![Repository Setup button](https://mintcdn.com/codspeed/SwdNrtJu0iSVsYr5/assets/github-connect-repo.png?fit=max\&auto=format\&n=SwdNrtJu0iSVsYr5\&q=85\&s=291bd83ddc1141ab0d49028e4b4da39c)

### Automated setup

> [!TIP]
>
> The [Performance Agent](https://codspeed.io/docs/ai/performance-agent.md) analyzes your repository,
> configures benchmarks, generates a CI workflow, and opens a pull request
> automatically. No manual configuration required.

1. From the repository setup screen, click **Start AI Setup** to let the
   Performance Agent handle the configuration:

   ![The setup modal showing AI Setup and Manual Setup options, with the Start AI Setup button highlighted](https://mintcdn.com/codspeed/GE_LrYDPyn_qQoG5/assets/wizard-ai-setup.png?fit=max\&auto=format\&n=GE_LrYDPyn_qQoG5\&q=85\&s=4bc6c5420b3a1e64fdcae8ab04eb5d9f)

2. The Performance Agent analyzes your repository and configures it:

   ![The setup modal showing AI Setup and Manual Setup options, with the Start AI Setup button highlighted](https://mintcdn.com/codspeed/GE_LrYDPyn_qQoG5/assets/wizard-in-progress.png?fit=max\&auto=format\&n=GE_LrYDPyn_qQoG5\&q=85\&s=70dabc708d7debde939b371466b81f6d)

3. The Performance Agent opens a setup **pull request**:

   ![Pull Request Result on Installation](https://mintcdn.com/codspeed/jKaxX6yy-Kzw1C-0/assets/quickstart-new-installation-pr.png?fit=max\&auto=format\&n=jKaxX6yy-Kzw1C-0\&q=85\&s=039a17923b6efd4dea35bb846593382e)

4. Review and merge the pull request to complete setup.

#### How it works

The Performance Agent handles the full setup process automatically:

1. **Detects existing benchmarks**: finds and configures your benchmarks in the
   language and framework you're already using.
2. **Creates benchmarks if needed**: generates appropriate benchmark files when
   none exist in the repository.
3. **Generates CI workflows**: creates optimized GitHub Actions or GitLab CI
   configurations tailored to your setup.
4. **Opens a pull request**: submits all changes for your review before anything
   is merged.

### Manual setup

If you prefer to configure CodSpeed yourself, follow the steps below. This
example uses a Python repository with `pytest`.

#### Create performance tests

1. Install the CodSpeed plugin for `pytest`:

   ```sh theme={null}
   pip install pytest-codspeed
   ```

2. Write a performance test using the `@pytest.mark.benchmark` marker:

   ```python tests/test_sum_squares.py highlight={12} icon="python" theme={null}
   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: &#x20;

   ```shellsession title=terminal icon="square-terminal" theme={null}
   $ 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 ====================
   ```

   Your first performance test is ready. Next, track it in CI with CodSpeed.

#### Run the tests in your CI

1. Create a new GitHub Actions workflow file to run your benchmarks:

   ```yaml .github/workflows/codspeed.yml icon="github" highlight={24,25,26,27,28} theme={null}
   name: CodSpeed Benchmarks

   on:
     push:
       branches:
         - "main" # or "master"
     pull_request:

   jobs:
     benchmarks:
       name: Run benchmarks
       runs-on: ubuntu-latest
       permissions: # optional for public repositories
         contents: read # required for actions/checkout
         id-token: write # required for OIDC authentication with CodSpeed
       steps:
         - uses: actions/checkout@v7
         - name: Setup Python
           uses: actions/setup-python@v7
           with:
             python-version: "3.13"
         - name: Install dependencies
           run: pip install pytest pytest-codspeed
         - name: Run the benchmarks
           uses: CodSpeedHQ/action@v5
           with:
             mode: simulation
             run: pytest tests/ --codspeed
   ```

2. Create a Pull Request installing the workflow to the repository and wait for
   the report in the comments:

   ![Pull Request Result on Installation](https://mintcdn.com/codspeed/jKaxX6yy-Kzw1C-0/assets/quickstart-new-installation-pr.png?fit=max\&auto=format\&n=jKaxX6yy-Kzw1C-0\&q=85\&s=039a17923b6efd4dea35bb846593382e)

3. Merge it and congrats, CodSpeed is installed!

#### Introduce a performance regression

1. Let's change the implementation of the `sum_squares` with a more concise and
   elegant one:

   ```python tests/test_sum_squares.py icon="python" theme={null}
   def sum_squares(arr):
       """Sum the squares of the numbers in an array."""
       total = 0 # [!code --:4]
       for x in arr:
           total += x * x
       return total
       return sum(map(lambda x: x**2, arr)) # [!code ++]
   ```

2. Open a Pull Request and wait for the CodSpeed report:

![Pull Request Regression Result](https://mintcdn.com/codspeed/jKaxX6yy-Kzw1C-0/assets/quickstart-regression-pr.png?fit=max\&auto=format\&n=jKaxX6yy-Kzw1C-0\&q=85\&s=7e5b2928d21552a5ec8e27e859448bbf)

Pull Request Performance Report showing the performance regression

Before merging, the report shows this new implementation is slower.

![Pull Request Checks failing because of the performance regression](https://mintcdn.com/codspeed/q5Q3QnyKsjTld2tv/assets/quickstart-regression-checks.png?fit=max\&auto=format\&n=q5Q3QnyKsjTld2tv\&q=85\&s=cafac36f9a791d06187e998b6ee8d6d7)

Pull Request Checks failing because of the performance regression

Merging it would have introduced a performance regression, but CodSpeed caught it before it shipped.

> [!TIP]
>
> This behavior can be enforced by configuring [performance
> checks](https://codspeed.io/docs/features/performance-checks.md).

## Next Steps

> [card] [What is CodSpeed?](https://codspeed.io/docs/what-is-codspeed.md)
>
> Learn how CodSpeed works

> [card] [pytest-codspeed documentation](https://codspeed.io/docs/benchmarks/python.md)
>
> Learn more about how to create performance tests with pytest-codspeed

> [card] [Explore the Performance Metrics](https://codspeed.io/docs/features/understanding-the-metrics.md)
>
> Understand the performance metrics generated by CodSpeed

> [card] [Enforce Performance Checks](https://codspeed.io/docs/features/performance-checks.md)
>
> Make sure you or team members never merge unexpected performance
> regressions.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.