> ## 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.

# Running Benchmarks in Buildkite

> Learn how to setup CodSpeed and run benchmarks within your Buildkite CI workflow

Running benchmarks in CI environments presents unique challenges due to the
inherent noise and variability of shared cloud infrastructure. Standard hosted
runners can exhibit significant performance variance.

> [!TIP]
>
> Read our detailed post on [how CI noise affects benchmark
> consistency](https://codspeed.io/blog/benchmarks-in-ci-without-noise).

[CodSpeed instruments](https://codspeed.io/docs/instruments.md) are designed to mitigate these challenges
and gather accurate performance data even in noisy environments. The easiest way
to get started running benchmarks in Buildkite is to use the
[CodSpeed Runner](https://github.com/CodSpeedHQ/codspeed) directly.

## Setup

> [!NOTE]
>
> For now, only the following OS and versions are supported on the agents:
>
> * Ubuntu 22.04 and later
> * Debian 12 and later

### 1. Setup the `CODSPEED_TOKEN` secret

First, you need to get your CodSpeed Token. There are multiple ways to retrieve
it:

* Once you enable a repository on CodSpeed, you'll be prompted to copy the token
* You can also find it on the repository settings page

![Upload Token from the settings page](https://mintcdn.com/codspeed/jKaxX6yy-Kzw1C-0/assets/upload-token.png?fit=max\&auto=format\&n=jKaxX6yy-Kzw1C-0\&q=85\&s=84e746ad14c38862e9e72776ee7b1f38)

> [!WARNING]
>
> **Token Scope**: Be mindful that a token is scoped to a specific repository.
> Make sure that you are on the correct repository settings page when copying the
> token.

Then, create a new
[pipeline secret with your preferred method](https://buildkite.com/docs/pipelines/secrets)
with the name `CODSPEED_TOKEN` and the value of your token.

### 2. Install the `codspeed-runner` CLI in your agent

Install the CLI on your agent:

```bash theme={null}
curl -fsSL https://codspeed.io/v5.8.0/install.sh | sh
```

Refer to the [releases page](https://github.com/CodSpeedHQ/codspeed/releases) to
see all available versions.

### 3. Create the benchmarks pipeline

In a new or existing pipeline, add a step that will run your benchmarks with
`codspeed-runner`:

```yml .buildkite/pipeline.yml theme={null}
steps:
  - label: "Run benchmarks with CodSpeed"
    command: |
      ... # your build commands
      codspeed-runner --token=$CODSPEED_TOKEN -- <Insert your benchmark command here>
```

### 3. Check the results

Once the workflow is created, your pull requests will receive a performance
report comment and will also receive some additional checks:

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

![Pull Request Result](https://mintcdn.com/codspeed/jKaxX6yy-Kzw1C-0/assets/pr-status-check-success.png?fit=max\&auto=format\&n=jKaxX6yy-Kzw1C-0\&q=85\&s=a74b568e364c0b068623bd31ee869361)

## Next Steps

> [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

> [card] [Explore Profiling](https://codspeed.io/docs/features/profiling.md)
>
> Get detailed flamegraphs and performance traces for your benchmarks

> [card] [Shard the execution of your benchmarks](https://codspeed.io/docs/features/sharded-benchmarks.md)
>
> Run your benchmarks in parallel to speed up your CI


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