> ## 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).
</Tip>

[CodSpeed instruments](/instruments) 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

<Info>
  For now, only the following OS and versions are supported on the agents:

  * Ubuntu 22.04 and later
  * Debian 12 and later
</Info>

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

<img src="https://mintcdn.com/codspeed/jKaxX6yy-Kzw1C-0/assets/upload-token.png?fit=max&auto=format&n=jKaxX6yy-Kzw1C-0&q=85&s=84e746ad14c38862e9e72776ee7b1f38" className="rounded-xl w-full max-w-xl mx-auto" alt="Upload Token from the settings page" width="1442" height="426" data-path="assets/upload-token.png" />

<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.
</Warning>

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 by running the following commands:

```bash theme={null}
CODSPEED_RUNNER_VERSION=<insert-version> # refer to https://github.com/CodSpeedHQ/codspeed/releases for available versions
curl -fsSL https://codspeed.io/$CODSPEED_RUNNER_VERSION/install.sh | bash
```

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:

<img src="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" className="rounded-xl w-full max-w-lg mx-auto" alt="Pull Request Result" width="1744" height="820" data-path="assets/pr-comment-new-installation.png" />

<img src="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" className="rounded-xl w-full max-w-md mx-auto" alt="Pull Request Result" width="1408" height="690" data-path="assets/pr-status-check-success.png" />

## Next Steps

<Columns cols={2}>
  <Card title="Explore the Performance Metrics" href="/features/understanding-the-metrics/" icon="chart-line">
    Understand the performance metrics generated by CodSpeed
  </Card>

  <Card title="Enforce Performance Checks" href="/features/performance-checks/" icon="shield-check">
    Make sure you or team members never merge unexpected performance regressions
  </Card>

  <Card title="Explore Profiling" href="/features/profiling" icon="bars-sort">
    Get detailed flame graphs and performance traces for your benchmarks
  </Card>

  <Card title="Shard the execution of your benchmarks" href="/features/sharded-benchmarks/" icon="layer-group">
    Run your benchmarks in parallel to speed up your CI
  </Card>
</Columns>
