Skip to main content
Keep your criterion or divan benchmarks as they are, add one crate, and run them with cargo codspeed in GitHub Actions. Every pull request then gets a comparison against main, with a flamegraph for each benchmark. The CPU simulation instrument runs each benchmark once on a standard GitHub runner, and the result repeats exactly from run to run.

Swap the criterion crate

Add the compatibility layer under the name criterion, so your benchmark code doesn’t change:
Under plain cargo bench, the layer passes straight through to criterion, so local runs behave as before. divan has its own layer, codspeed-divan-compat, and bencher is supported too.

Build and run locally

Install the cargo subcommand, then build and run the benchmarks under CodSpeed:

Add the workflow

Create .github/workflows/codspeed.yml:
.github/workflows/codspeed.yml
The push trigger on main gives every pull request a baseline to compare against. workflow_dispatch lets CodSpeed backtest older commits to build the first data points. id-token: write lets the action authenticate with OIDC, so a private repository doesn’t need a stored token. Public repositories can skip the permissions block.

Catch regressions on every pull request

Once the workflow runs, each pull request gets a performance report comment and a status check named “CodSpeed Performance Analysis”. Make that check required in your branch protection, and a regression above the threshold blocks the merge. The default threshold is 10%, and you can set one per benchmark.

What Ruff runs

Ruff benchmarks its formatter, lexer, linter and parser this way. Its workflow builds them with cargo codspeed build -m simulation -m memory and runs the action with mode: "simulation,memory", so one job reports both CPU and memory results.

When to use walltime instead

CPU simulation leaves out system calls. If your benchmark spends its time in I/O, threads or the kernel, run it with mode: walltime on a Macro Runner. Walltime measures elapsed time, and the runner is a bare-metal machine with isolated cores. Next, read what each number in the report measures.