OSS探訪GitHubでログイン

unit test風のC++ APIでmicrobenchmarkを登録しtime・iteration・counter・statisticsを測定する

スコアの見方

OSS規模スコアはStars・Watchers・Forks・Contributorsを対数圧縮して重み付けした現在の規模指標(上限なし)です。発掘スコアは現在のOSS規模スコアから発掘時点のOSS規模スコアを引いた値、更新ペースは直近30日Commit数、成長モメンタムは直近の観測期間におけるOSS規模スコア差、OSS健全度は取得できた更新状況・Community Health・Releaseの0〜100評価です。

Stars
10,449
主要言語
C++
ライセンス
Apache-2.0
リポジトリ最終更新
2026/10/02
ページ内ナビ

概要

Google BenchmarkはC++ code snippetのmicrobenchmarkをunit testに近い形式で定義・実行するlibraryです。BENCHMARK macro、fixture、argument、thread、manual timing、custom counter/statisticsを使い、console/JSON等のresultを比較・分析できます。

特徴と向いている用途

公式資料に基づく紹介・実機未検証 · 内容確認日:

主な特徴

benchmark functionを登録してiteration loopを自動管理する

benchmark::StateとBENCHMARK macroで測定対象を登録し、library側がiteration数やtimingを調整してresultを出力します。

出典:[1][2]

argument・fixture・thread・manual timing・counterを使う

parameterized benchmark、fixture、multithread benchmark、manual timing、custom counters、complexity/statistics等を組み合わせて測定条件を表現できます。

出典:[2]

console・JSON出力とfilter/dry-runで測定を制御する

outputをconsole/JSON等へ切り替え、regex filterで対象を絞れます。--benchmark_dry_runは1 iteration/1 repetitionで実行経路を素早く確認できます。

出典:[2]

向いている用途

C++の関数・algorithm・container実装差を再現可能なmicrobenchmarkで比較したい場合に向く

performance regression testやimplementation比較をsource codeとして管理し、CIやlocal machineで同一benchmarkを繰り返したい用途に適します。

出典:[1][2]

導入前の確認

library利用はC++11可能だがlibrary build自体はC++17が必要

v1.9.5 READMEはconsumer codeでC++11を利用できる一方、Google Benchmark自体のbuildにはC++17 compiler/standard libraryを要求しています。

出典:[1][4]

Debug buildやCPU scalingなど測定環境によるvarianceを管理する

defaultはDebug buildでwarningが出るためperformance測定ではRelease buildを使います。microbenchmarkはCPU frequency、background load、optimizer等の影響を受けるため、絶対値より条件を固定した比較を重視します。experimental v2 branchにはstability guaranteeがありません。

出典:[1][2]

参考にした公式資料

  1. [1]Google Benchmark v1.9.5 README(2026-10-04)
  2. [2]Google Benchmark v1.9.5 user guide(2026-10-04)
  3. [3]Google Benchmark v1.9.5 release(2026-10-04)
  4. [4]Google Benchmark v1.9.5 CMake configuration(2026-10-04)
  5. [5]Google Benchmark Apache 2.0 license(2026-10-04)
編集部からの補足

性能比較ではDebug buildの値を使わずRelease buildを基本にし、CPU scalingやbackground loadなど測定環境を揃えてください。consumerはC++11でも、library buildはC++17が必要です。

3ステップで試す

  1. 1

    Google Benchmark v1.9.5を取得する

    stable release tagへ固定します。

    git clone --depth 1 --branch v1.9.5 https://github.com/google/benchmark.git benchmark-1.9.5
  2. 2

    Release libraryをtestsなしでbuildする

    performance測定向けにRelease buildを使い、GoogleTest依存のtest buildは省きます。

    cmake -S benchmark-1.9.5 -B benchmark-1.9.5/build -DCMAKE_BUILD_TYPE=Release -DBENCHMARK_ENABLE_TESTING=OFF && cmake --build benchmark-1.9.5/build -j2
  3. 3

    最小benchmarkをdry runする

    1 iteration/1 repetitionのdry runだけを実行し、長時間benchmarkは行いません。

    printf '#include <benchmark/benchmark.h>\nstatic void BM_Add(benchmark::State& s){for(auto _ : s){int x=1+1; benchmark::DoNotOptimize(x);}}\nBENCHMARK(BM_Add);\nBENCHMARK_MAIN();\n' > benchmark-demo.cc && c++ -std=c++11 -Ibenchmark-1.9.5/include benchmark-demo.cc -Lbenchmark-1.9.5/build/src -lbenchmark -lpthread -o benchmark-demo && ./benchmark-demo --benchmark_dry_run
公式READMEで確認

成長

成長の推移 · 直近30日

10,449 Stars

推移データを蓄積中です。

開発アクティビティ

直近90日・週次

Commit(直近30日)
12
Open PR
23

開発アクティビティを蓄積中です。

Built with

カテゴリとタグ

GitHubデータ

GitHubのデータGitHubの詳細データを見る

GitHub Topics

  • benchmark
Stars
10,449
Forks
1,810
Watchers
204
Open Issues
151
Contributors
358
所有者種別
Organization
主要言語
C++
ライセンス
Apache-2.0
リポジトリ最終更新
2026/10/02

このOSSの使い方や活用事例をMarkdownで投稿できます。管理者が承認した後に公開されます。

情報の誤りを報告

掲載内容に誤りや古い情報があればお知らせください。

このページを読んで、次に何をすればよいか分かりましたか?