|
benchmark 1.10.0
|
Google Benchmark provides Bazel targets for both the benchmark library and the optional default main function:
Use @google_benchmark//:benchmark when the benchmark target defines its own main function, including through BENCHMARK_MAIN(). Use @google_benchmark//:benchmark_main when the benchmark target should use the default Google Benchmark entry point.
With Bzlmod enabled, add Google Benchmark to your MODULE.bazel file:
Replace <VERSION> with the Google Benchmark release version you want to use.
Then depend on the Bazel target from a cc_binary or cc_test:
The source file should register benchmarks, but it should not call BENCHMARK_MAIN() when linking against @google_benchmark//:benchmark_main:
Run the benchmark with Bazel:
Pass Google Benchmark flags after Bazel's -- separator:
Projects that still use WORKSPACE can declare Google Benchmark as an external repository and load its dependencies from bazel/benchmark_deps.bzl:
Use the same <VERSION> value without the leading v; the archive URL adds the tag prefix explicitly.
After declaring the repository, use the same target labels shown above: @google_benchmark//:benchmark or @google_benchmark//:benchmark_main.
When using Bazel, enable libpfm support by adding --define pfm=1 to the build or run command. See Perf Counters for more details.