go test benchmarks run under CodSpeed as they are, with no code change
and no extra package. In GitHub Actions, they run with the walltime instrument
on a Macro Runner, a bare-metal machine with isolated CPU cores and a fixed
clock. On the Cortex-A72 runner, noise stays under 1%, so a 3.3% change stands
out with 99% confidence.
Write the benchmark with testing.B
Benchmark the code your service runs on every request. Here’s a benchmark for decoding a request body withencoding/json:
b.Loop() on Go 1.24 and later. The older for i := 0; i < b.N; i++ loop
works too.
Run it locally under CodSpeed
Install the CodSpeed CLI and run the same command you use today:Add the workflow
Create.github/workflows/codspeed.yml:
.github/workflows/codspeed.yml
push trigger on main gives every pull request a baseline.
workflow_dispatch lets CodSpeed backtest older commits for the first data
points. Keep the job on one runner label, since a different machine shifts the
baseline.
For lower noise, switch runs-on to
codspeed-macro-x64-ryzen-9950x-ubuntu-24-04. That runner keeps noise under
0.5%, so a 1.7% change stands out with 99% confidence.
Catch regressions on the pull request
Each pull request gets a performance report comment and a status check named “CodSpeed Performance Analysis”. Walltime runs record a flamegraph, so a slower benchmark comes with the functions that got slower. If flamegraphs look cut short on the ARM64 runner, setCODSPEED_PERF_UNWINDING_MODE: fp in the step’s
env.
What Bifrost runs
Bifrost, an open-source AI gateway written in Go, runs its request hot path benchmarks this way: payload parsing, provider request and response conversion, SSE framing and key selection. Its workflow runsgo test -bench under the
walltime instrument on a Macro Runner, on every pull request and on pushes to
its main branches. A matrix splits the packages into four jobs, so one module’s
failure doesn’t hide the others’ results.
Flags to know
The Go integration reads-bench to pick benchmarks and -benchtime to set how
long each one runs. It ignores other go test flags, such as -count,
-benchmem or -cpu, with a warning. To split a long suite across jobs, give
each job its own -bench pattern.
Next, see how
Macro Runners keep walltime results stable.