FeaturesBlogDocsPricingExploreChangelog
Login
Get Started

Changelog

New updates and improvements released to Codspeed.
Follow us on

C++ Support

C++ Support

You can now use CodSpeed to benchmark C++ codebases thanks to our new integration with google/benchmark`.

Quick Start

CodSpeed's C++ support works out of the box with CMake:

# Fetch the CodSpeed compatibility layer
FetchContent_Declare(
    google_benchmark
    GIT_REPOSITORY https://github.com/CodSpeedHQ/codspeed-cpp
    SOURCE_SUBDIR google_benchmark
    GIT_TAG main # Or chose a specific version or git ref
)
FetchContent_MakeAvailable(google_benchmark)

# Declare your benchmark executable and its sources here
add_executable(bench_fibo benches/fibo.cpp)

# Link your executable against the `benchmark::benchmark`
target_link_libraries(bench_fibo benchmark::benchmark)

You can then write your benchmarks in C++ using the google/benchmark API. Here's an example:

#include <benchmark/benchmark.h>

static void BM_Fib(benchmark::State& state) {
  auto fib = [](int n) {
    return n < 2 ? n : fib(n - 1) + fib(n - 2);
  };

  for (auto _ : state)
    benchmark::DoNotOptimize(fib(10));
}

BENCHMARK(BM_Fib);
BENCHMARK_MAIN();

This can then run both locally and in CI environments using the CodSpeed Runner. Check out the documentation on integrating the runner in CI environments.

Real World Examples

Here are a few example repositories of real-world C++ projects:

  • boost-benches: a collection of benchmarks for the Boost C++ Libraries
  • opencv-benches: a collection of benchmarks for the OpenCV library

Check out our C++ documentation for more details.

Stop Guessing,
Start Measuring.

Resources Home PricingDocs BlogGitHub Changelog Advent 🎄

{176023}Analyzed Commits
Explore Repos

Backed by
Copyright © 2025 CodSpeed Technology