A test suite that measures the speed and statistical quality of hash functions, with a large table of tested implementations.
google/benchmark
A C++ library for writing microbenchmarks that time small code snippets, similar in structure to unit tests.
- Stars
- 10,499
- Forks
- 1,825
- Open issues
- 174
- Last commit
- 8 hours ago
What is it?
Google Benchmark is a C++ library for measuring the performance of small code snippets. You write a function that runs the code under test inside a loop, register it with the BENCHMARK macro, and the library handles timing, iteration counts and result reporting. Its API structure resembles Google Test, so it fits naturally alongside existing unit tests.
The library builds with CMake and can also be used through Bazel or installed as a system package and imported with find_package. It requires a C++17 toolchain to build, while the library's API can be used from C++11 code. The project also provides Python bindings and additional tooling for working with benchmark results.
It is aimed at C++ developers who need to compare implementations or track performance of a specific function, rather than measuring whole applications.
Key features
- 01Registers benchmark functions with a simple BENCHMARK macro and a loop-based API.
- 02Builds with CMake and integrates with Bazel and find_package.
- 03Supports sanitizer and link-time optimization build options.
- 04Provides Python bindings and additional tooling documentation.
- 05Offers assembly testing documentation for checking generated code.
Use cases
- Comparing two C++ implementations of the same function to see which is faster.
- Adding performance regression checks for hot code paths alongside unit tests.
- Measuring the cost of individual algorithms or data structure operations.
Quick start
- 1
Clone the library repository
git clone https://github.com/google/benchmark.git - 2
Go into the library root directory
cd benchmark - 3
Generate build system files with CMake and download dependencies
cmake -DBENCHMARK_DOWNLOAD_DEPENDENCIES=on -DCMAKE_BUILD_TYPE=Release -S . -B "build" - 4
Build the library
cmake --build "build" --config Release
Things to know
- The library requires a C++17 compiler and standard library to build.
- The experimental v2 branch offers no stability guarantees and may break the API at any time.
In collections
Topics
FAQ
- What is benchmark?
- A C++ library for writing microbenchmarks that time small code snippets, similar in structure to unit tests. Google Benchmark is a C++ library for measuring the performance of small code snippets. You write a function that runs the code under test inside a loop, register it with the BENCHMARK macro, and the library handles timing, iteration counts and result reporting. Its API structure resembles Google Test, so it fits naturally alongside existing unit tests.
- Is benchmark free to use? What license does it have?
- benchmark is open source under the Apache-2.0 license. Check the license terms before using it in commercial products.
- Is benchmark still maintained?
- Actively maintained. The last commit to benchmark was on Nov 6, 2026.
- What can I use benchmark for?
- Comparing two C++ implementations of the same function to see which is faster. Adding performance regression checks for hot code paths alongside unit tests. Measuring the cost of individual algorithms or data structure operations.
- How do I install benchmark?
- Clone the library repository: git clone https://github.com/google/benchmark.git Go into the library root directory: cd benchmark Generate build system files with CMake and download dependencies: cmake -DBENCHMARK_DOWNLOAD_DEPENDENCIES=on -DCMAKE_BUILD_TYPE=Release -S . -B "build" Build the library: cmake --build "build" --config Release
- Where can I get benchmark?
- The source code and installation instructions are on GitHub: https://github.com/google/benchmark
Summary generated by AI from the project's README. GitHub stats refresh daily.
Related projects
Facebook's open-source C++20 library of core components, complementing Boost and std, used extensively inside Meta.
A header-based unit testing framework for C++ with simple assertions, BDD-style macros, and basic micro-benchmarking.
Official Qt skill packs that teach AI coding tools like Claude Code, Codex CLI and Copilot Qt C++, QML, testing and design conventions.
A command-line tool for benchmarking commands with statistical analysis, warmup runs, and exports to CSV, JSON, Markdown and AsciiDoc.
A .NET library for turning C# methods into reproducible benchmarks, with automatic warm-up, statistics and result reports.