Authentication
In order to upload benchmark results to CodSpeed, the CircleCI job needs to authenticate with CodSpeed. There are two supported methods for authentication: OpenID Connect (OIDC) and static CodSpeed tokens.OIDC (Recommended)
CodSpeed recommends using OpenID Connect (OIDC) for authentication. Using this method, a token is generated on-the-fly during the workflow run. This token is then used to authenticate securely with CodSpeed without needing to store long-lived credentials, but grants no additional permissions to the workflow. On CircleCI, this works by default: a job that sets noCODSPEED_TOKEN
authenticates with an OIDC token, and there is nothing to configure for it. If a
job cannot use OIDC, authenticate it with a CodSpeed token.
CodSpeed token
Some jobs cannot use OIDC and need a static CodSpeed token instead:- Pull requests opened from a fork, whose token names the fork rather than your repository.
- Pipelines triggered by a custom webhook, whose token names no repository at all.
- Jobs running on an image that does not ship the
circleciCLI, which the CodSpeed CLI needs to request the token.

CODSPEED_TOKEN. The CodSpeed CLI reads it from the job environment.
Project settings
Pipeline trigger
CodSpeed recommends the PR opened or pushed to, default branch and tag pushes event for the benchmarks pipeline: it builds the default branch, recording the baselines, and builds pull requests, which is what CodSpeed reports on. See the setup guide for how to set it.Running the benchmarks in an existing pipeline
You can add the benchmarks to a pipeline you already have. Its trigger covers every job in it, so restricting the benchmarks to pull requests restricts the rest too. CircleCI does not rebuild a branch it has already built, so a branch built before you changed the trigger receives no performance report until you push a new commit to it.Legacy GitHub OAuth projects
CircleCI has two types of GitHub integration: the GitHub App, which the setup guide follows, and the GitHub OAuth app it replaces. CodSpeed supports both. An OAuth project holds a single pipeline, and its configuration has to live in.circleci/config.yml. The benchmarks job goes in that file, alongside your
other jobs, rather than in a dedicated one:
.circleci/config.yml
CODSPEED_TOKEN unset, it authenticates
with an OIDC token. Its trigger is the
one that pipeline already has, so
the same tradeoff applies.
To bypass these restrictions, CodSpeed recommends installing the CircleCI GitHub
App, which can be installed alongside an existing GitHub OAuth pipeline, and
giving the benchmarks a pipeline of their own as the
setup guide does.
Advanced
CLI version
The examples pin the CLI version in the install URL, which is what CodSpeed recommends: the tools an instrument needs are pinned to it, so a version that moves under you can shift the measurements. All versions are listed on the releases page. To install the latest version on every job instead, drop the version from the URL:.circleci/codspeed.yml
codspeed on the PATH of the steps that follow, since
every run step starts a fresh shell. Refer to the CircleCI documentation on
setting an environment variable in a shell command
for more details.
Running benchmarks in parallel CI jobs
With CircleCI, you can split your benchmarks across multiple jobs, either with a matrix of jobs or with theparallelism key.
For example with pytest, using a matrix. The --test-group options come from
pytest-test-groups,
which the benchmarks job needs installed alongside your other dependencies:
.circleci/codspeed.yml
parallelism key works as well, and CodSpeed keeps the results of its
containers apart. Since CircleCI numbers them from 0, shard from
$CIRCLE_NODE_INDEX and $CIRCLE_NODE_TOTAL:
Caching the installed instruments
The CodSpeed CLI installs the tools its instruments need, such as valgrind for CPU simulation, on every job. Install them in a step of their own withcodspeed setup, pointed at a directory you cache, and later jobs restore them
instead of installing them again:
.circleci/codspeed.yml
--setup-cache-dir, since the instruments it installs
are already in place when the benchmarks run. Caching right after it, rather
than after the benchmarks, means a benchmark failure does not cost the next run
the install.
The tools are pinned to the CLI version, so include that version in the cache
key when you install a pinned CLI rather than the latest one.
Executors
Both themachine and the docker executor are supported:
machine, with an Ubuntu 22.04 or later image, for exampleubuntu-2404:current.docker, with an image based on Ubuntu 22.04 or later, or Debian 12 or later. CircleCI’scimgimages qualify.