Need help with benchmark?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

5.8K Stars 1.1K Forks Apache License 2.0 1.2K Commits 124 Opened issues


A microbenchmark support library

Services available


Need anything else?

Contributors list


build-and-test bazel pylint test-bindings

Build Status Coverage Status

A library to benchmark code snippets, similar to unit tests. Example:


static void BM_SomeFunction(benchmark::State& state) { // Perform setup here for (auto _ : state) { // This code gets timed SomeFunction(); } } // Register the function as a benchmark BENCHMARK(BM_SomeFunction); // Run the benchmark BENCHMARK_MAIN();

Getting Started

To get started, see Requirements and Installation. See Usage for a full example and the User Guide for a more comprehensive feature overview.

It may also help to read the Google Test documentation as some of the structural aspects of the APIs are similar.


Discussion group

IRC channels: * libera #benchmark

Additional Tooling Documentation

Assembly Testing Documentation


The library can be used with C++03. However, it requires C++11 to build, including compiler and standard library support.

The following minimum versions are required to build the library:

  • GCC 4.8
  • Clang 3.4
  • Visual Studio 14 2015
  • Intel 2015 Update 1

See Platform-Specific Build Instructions.


This describes the installation process using cmake. As pre-requisites, you'll need git and cmake installed.

See for more details regarding supported versions of build tools.

# Check out the library.
$ git clone
# Go to the library root directory
$ cd benchmark
# Make a build directory to place the build output.
$ cmake -E make_directory "build"
# Generate build system files with cmake, and download any dependencies.
$ cmake -E chdir "build" cmake -DBENCHMARK_DOWNLOAD_DEPENDENCIES=on -DCMAKE_BUILD_TYPE=Release ../
# or, starting with CMake 3.13, use a simpler form:
# cmake -DCMAKE_BUILD_TYPE=Release -S . -B "build"
# Build the library.
$ cmake --build "build" --config Release

This builds the

libraries and tests. On a unix system, the build directory should now look something like this:

Next, you can run the tests to check the build.

$ cmake -E chdir "build" ctest --build-config Release

If you want to install the library globally, also run:

sudo cmake --build "build" --config Release --target install

Note that Google Benchmark requires Google Test to build and run the tests. This dependency can be provided two ways:

  • Checkout the Google Test sources into
  • Otherwise, if
    is specified during configuration as above, the library will automatically download and build any required dependencies.

If you do not wish to build and run the tests, add


Debug vs Release

By default, benchmark builds as a debug library. You will see a warning in the output when this is the case. To build it as a release library instead, add

when generating the build system files, as shown above. The use of
--config Release
in build commands is needed to properly support multi-configuration tools (like Visual Studio for example) and can be skipped for other build systems (like Makefile).

To enable link-time optimisation, also add

when generating the build system files.

If you are using gcc, you might need to set

cmake cache variables, if autodetection fails.

If you are using clang, you may need to set

cmake cache variables.

Stable and Experimental Library Versions

The main branch contains the latest stable version of the benchmarking library; the API of which can be considered largely stable, with source breaking changes being made only upon the release of a new major version.

Newer, experimental, features are implemented and tested on the

branch. Users who wish to use, test, and provide feedback on the new features are encouraged to try this branch. However, this branch provides no stability guarantees and reserves the right to change and break the API at any time.


Basic usage

Define a function that executes the code to measure, register it as a benchmark function using the

macro, and ensure an appropriate
function is available:

static void BM_StringCreation(benchmark::State& state) { for (auto _ : state) std::string empty_string; } // Register the function as a benchmark BENCHMARK(BM_StringCreation);

// Define another benchmark static void BM_StringCopy(benchmark::State& state) { std::string x = "hello"; for (auto _ : state) std::string copy(x); } BENCHMARK(BM_StringCopy);


To run the benchmark, compile and link against the

library (libbenchmark.a/.so). If you followed the build steps above, this library will be under the build directory you created.
# Example on linux after running the build steps above. Assumes the
# `benchmark` and `build` directories are under the current directory.
$ g++ -std=c++11 -isystem benchmark/include \
  -Lbenchmark/build/src -lbenchmark -lpthread -o mybenchmark

Alternatively, link against the

library and remove
above to get the same behavior.

The compiled executable will run all benchmarks by default. Pass the

flag for option information or see the User Guide.

Usage with CMake

If using CMake, it is recommended to link against the project-provided

targets using
. It is possible to use
to import an installed version of the library.
find_package(benchmark REQUIRED)
will incorporate the library directly in to one's CMake project.
Either way, link to the library as follows.
target_link_libraries(MyTarget benchmark::benchmark)

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.