codspeed.yml configuration file, and run them locally
or in CI.
This approach works for any language or toolchain, even if it does not have a
dedicated integration yet, e.g., Zig, OCaml, or Swift. It is also a good fit for
benchmarking a program end to end, like a CLI tool or a compiler.
Benchmarks defined this way measure a whole command, including process
startup. If your language has a dedicated
integration, prefer it to benchmark individual
functions. Otherwise, you can also
build a custom harness to measure
only a subpart of your program.If you would like a dedicated integration for your language, let us know on
Discord or
open a GitHub issue.
Installing the CodSpeed CLI
Install the CodSpeed CLI using the installation script:codspeed auth login.
Defining the benchmarks
Create acodspeed.yml file at the root of your repository. Each item in the
benchmarks list describes a command to benchmark:
codspeed.yml
exec field is the command to run. Build the executable beforehand with
your usual toolchain, CodSpeed measures the command as is.
See the CLI configuration reference for all available
fields and options.
Running the benchmarks locally
Build your program, then run all the benchmarks defined in the configuration file with the walltime instrument:terminal
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. Here is an example of a GitHub Actions workflow that runs the benchmarks and reports the results to CodSpeed on every push to themain branch and every
pull request:
The walltime instrument runs on
CodSpeed Macro Runners, bare-metal machines that
deliver low-variance measurements:
Contrary to other CI usages, the
run input is intentionally omitted
here: this is what makes the action run the benchmarks defined in your
configuration file.Advanced
Benchmarking a subpart of your program
Benchmarks defined withexec measure the whole command, including process
startup. To measure only a specific section of your program, e.g., its core
processing loop, you can build a custom harness with the
instrument-hooks library.
A custom harness instruments your program directly: it tells CodSpeed exactly
when the measured section starts and stops. The library is a single C file that
integrates with virtually any language through FFI. Follow the
custom harness guide
to build one.
Since your program then embeds its own harness, declare it with entrypoint
instead of exec in the configuration file:
codspeed.yml
codspeed run instead of codspeed exec:
Next Steps
CodSpeed CLI
Explore all the commands, instruments, and configuration options of the
CodSpeed CLI.
Walltime instrument
Learn more about the walltime instrument and how to use it.
Profiling
Learn how to use flamegraphs and profiling data to optimize your code.
Performance checks
Catch regressions automatically on every pull request.