Skip to main content
The Go integration is still in early development, and only some go test CLI flags are supported. See the compatibility section for more information on how to ensure your benchmarks work with CodSpeed.Additionally, only the walltime instrument is currently supportedIf you have any feedback, please reach out to us via Discord or email our support.
Integrating CodSpeed into your Go codebase requires no modification. You can continue using go test and the testing package as you normally would. When running your benchmarks in CI with CodSpeed, your benchmarks will automatically be built and the reports will be sent to CodSpeed.

Creating benchmarks

You can just use the testing package to write benchmarks in Go. If the benchmarks are working with go test, then they will also automatically be detected by CodSpeed without any additional configuration. Here’s an example of a simple Fibonacci function benchmark:
fib_test.go
We recommend using b.Loop() as it’s more precise and efficient.Still, for i := 0; i < b.N; i++ is also supported for backward compatibility (before Go 1.24):
For a deeper dive into Go benchmarking, see the dedicated guide:

How to Benchmark Go with the testing Package

An in-depth guide to writing Go benchmarks: sub-benchmarks, parallel benchmarks, benchstat, pprof, and CodSpeed CI integration.

Testing the benchmarks locally

To run the benchmarks with CodSpeed locally, you need to install the codspeed runner:
terminal
You can then run your go test command with CodSpeed:
terminal
This will print all the benchmarks that can be run with CodSpeed and warnings if some benchmarks are not supported.

Running the benchmarks in your CI

To generate performance reports, you need to run the benchmarks in your CI. This allows CodSpeed to automatically run benchmarks and warn you about regressions during development.
If you want more details on how to configure the CodSpeed action, you can check out the Continuous Reporting section.
Here is an example of a GitHub Actions workflow that runs the benchmarks and reports the results to CodSpeed on every push to the main branch and every pull request:
Incomplete flamegraphs on ARM64?If your flamegraphs appear incomplete on ARM64 (e.g., on CodSpeed Macro runners), try setting the CODSPEED_PERF_UNWINDING_MODE environment variable to fp:
This switches from DWARF-based unwinding to frame-pointer-based unwinding, which produces more reliable call stacks for Go on ARM64. CodSpeed tries to detect this automatically, but it cannot catch every case.

Recipes

Sharding benchmarks in parallel CI jobs

If your benchmarks are taking too much time to run under the CodSpeed action, you can run them in parallel to speed up the execution. To parallelize your benchmarks, simply add filters to the go test command to only run a subset of benchmarks in each job.
CompatibilityWe only support the following flags for go test:
  • -bench (required)
If you run into issues or require certain features, please open an issue or join our Discord to get help.

Next steps

Walltime instrument

Learn more about the Walltime instrument and how to use it.

How to Benchmark Go with the testing Package

An in-depth guide to writing Go benchmarks with CodSpeed.

Dive into performance changes

Learn more about profiling and how to read flamegraphs.

Example repository with benchmarks

The example GitHub repository for this Gin Gonic API with benchmarks.