ページ内ナビ
概要
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を出力します。
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]
向いている用途
導入前の確認
library利用はC++11可能だがlibrary build自体はC++17が必要
v1.9.5 READMEはconsumer codeでC++11を利用できる一方、Google Benchmark自体のbuildにはC++17 compiler/standard libraryを要求しています。
参考にした公式資料
- [1]Google Benchmark v1.9.5 README(2026-10-04)
- [2]Google Benchmark v1.9.5 user guide(2026-10-04)
- [3]Google Benchmark v1.9.5 release(2026-10-04)
- [4]Google Benchmark v1.9.5 CMake configuration(2026-10-04)
- [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
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
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
最小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
成長
成長の推移 · 直近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で投稿できます。管理者が承認した後に公開されます。
あわせて探訪
- CodeceptJS4,242 Stars
共通タグ 1件 · 共通カテゴリ 2件
PlaywrightなどのE2E操作を利用者視点の
JavaScriptIステップへ統一するテストフレームワーク - WebMock4,049 Stars
共通タグ 1件 · 共通カテゴリ 2件
RubyのHTTP requestを実networkへ送らずstubし、method・URI・header・bodyに対する期待値をtestで検証する
Ruby - Fluent Assertions3,813 Stars
共通タグ 1件 · 共通カテゴリ 2件
C#.Should()から始まる読みやすいassertionで.NETのunit testに期待結果と失敗理由を表現する - Catch221,505 Stars
共通タグ 2件 · 共通カテゴリ 2件 · 同じ言語
C++の単体テスト・BDD・簡易ベンチマークを同じテスト実行環境で記述し、CMake/CTestへ組み込む
C++ - GoogleTest39,616 Stars
共通タグ 2件 · 共通カテゴリ 1件 · 同じ言語
C++のunit test・assertion・parameterized test・mockを統合するGoogleのtesting framework
C++ - Playwright97,062 Stars
共通タグ 1件 · 共通カテゴリ 2件
Chromium・Firefox・WebKitを一つのAPI/Test runnerで操作し、E2E test・script・agent browser automationを実行する
TypeScript
情報の誤りを報告
掲載内容に誤りや古い情報があればお知らせください。