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

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

Running benchmarks in CI environments presents unique challenges due to the
inherent noise and variability of shared cloud infrastructure. Standard
GitHub-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 GitHub Actions is to use the
[CodSpeed GitHub Action](https://github.com/CodSpeedHQ/action).

## 1. Create the benchmarks workflow

Create a new workflow to run the benchmarks for your repository.

You can do this by creating the `codspeed.yml` file in the `.github/workflows`
directory with the following content:

```yaml .github/workflows/codspeed.yml icon="github" highlight={27,28,29,30,31} theme={null}
name: CodSpeed Benchmarks

on:
  push:
    branches:
      - "main" # or "master"
  pull_request:
  # `workflow_dispatch` allows CodSpeed to trigger backtest
  # performance analysis in order to generate initial data.
  workflow_dispatch:

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
      # ...
      # Setup your environment here:
      #  - Configure your Python/Rust/Node version
      #  - Install your dependencies
      #  - Build your benchmarks (if using a compiled language)
      # ...
      - name: Run the benchmarks
        uses: CodSpeedHQ/action@v5
        with:
          mode: simulation
          run: <Insert your benchmark command here>
```

The most important step of this workflow is the usage of
[`CodSpeedHQ/action`](https://github.com/CodSpeedHQ/action). This action will
configure the CodSpeed environment and upload the benchmarks results.

> [!NOTE]
>
> Keep both triggers in the workflow's `on` section:
>
> * `push` on your default branch (e.g., `main`). These runs record the baseline
>   that every comparison is measured against.
> * `pull_request`. This is what reports the performance impact of a pull request,
>   measured against that baseline.
>
> If CodSpeed runs only on `pull_request` (or a manual `workflow_dispatch`), there
> are no runs on the default branch, so pull requests have no baseline to compare
> against and the default branch shows no results in CodSpeed.
>
> Learn more about
> [baseline report selection](https://codspeed.io/docs/features/understanding-the-metrics.md#baseline-report-selection).

> [!TIP]
>
> **Public repositories**
>
> CodSpeed allows tokenless uploads for public repositories, allowing runs to be
> triggered from public forks directly.
>
> To enable this, you can simply omit the `permissions` section.
>
> Learn more about
> [authentication methods](https://codspeed.io/docs/integrations/ci/github-actions/configuration.md#authentication).

### Sample configurations

For a complete workflow, with the steps that set up your language, see the page
of your benchmark framework:

* Python:
  [`pytest-codspeed`](https://codspeed.io/docs/benchmarks/python#running-the-benchmarks-in-your-ci)
* Rust: [`divan`](https://codspeed.io/docs/benchmarks/rust/divan#running-the-benchmarks-in-your-ci),
  [`criterion.rs`](https://codspeed.io/docs/benchmarks/rust/criterion#running-the-benchmarks-in-your-ci),
  [`bencher`](https://codspeed.io/docs/benchmarks/rust/bencher#running-the-benchmarks-in-your-ci)
* Node.js:
  [`vitest`](https://codspeed.io/docs/benchmarks/nodejs/vitest#running-the-benchmarks-in-your-ci),
  [`tinybench`](https://codspeed.io/docs/benchmarks/nodejs/tinybench#running-the-benchmarks-in-your-ci),
  [`benchmark.js`](https://codspeed.io/docs/benchmarks/nodejs/benchmarkjs#running-the-benchmarks-in-your-ci),
  [Playwright](https://codspeed.io/docs/benchmarks/nodejs/playwright.md#running-the-benchmarks-in-your-ci)
* [Go](https://codspeed.io/docs/benchmarks/go.md#running-the-benchmarks-in-your-ci)
* C++: [CMake](https://codspeed.io/docs/benchmarks/cpp.md#running-the-benchmarks-in-your-ci),
  [Bazel](https://codspeed.io/docs/benchmarks/cpp.md#running-the-benchmarks-in-your-ci-2)
* [Java](https://codspeed.io/docs/benchmarks/java.md#running-the-benchmarks-in-your-ci),
  [Kotlin](https://codspeed.io/docs/benchmarks/kotlin.md#running-the-benchmarks-in-your-ci),
  [Scala](https://codspeed.io/docs/benchmarks/scala.md#running-the-benchmarks-in-your-ci)
* Other languages:
  [CLI commands](https://codspeed.io/docs/benchmarks/cli-commands.md#running-the-benchmarks-in-your-ci)

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

## 3. Next Steps

Now that everything is up and running (and hopefully green 🎉), you can start
enhancing your workflow to get the most out of CodSpeed.

> [card] [Configure GitHub Actions for CodSpeed](https://codspeed.io/docs/integrations/ci/github-actions/configuration.md)
>
> Learn how to configure authentication methods and advanced options for
> GitHub Actions

> [card] [Macro Runners on GitHub Actions](https://codspeed.io/docs/integrations/ci/github-actions/macro-runners.md)
>
> Measure walltime on dedicated bare-metal machines

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