在发布模式下使用 Bazel 注册表中的 googlebenchmark

问题描述 投票:0回答:1

我正在使用 bazel 注册表中的 google 基准测试,但它是在调试模式下编译的。

要使用该库,我已将此行添加到

MODULE.bazel

bazel_dep(name = "google_benchmark", version = "1.8.3", repo_name = "com_google_google_benchmark")

然后在我的目标中我以这种方式使用它

cc_binary(
    name = "hello-world",
    srcs = [
        "hello-world.cpp",
    ],
    deps = [
        "@com_google_google_benchmark//:benchmark_main",
    ],
)

但是当我运行目标时,我收到这个经典警告:

Run on (16 X 4800 MHz CPU s)
CPU Caches:
  L1 Data 48 KiB (x8)
  L1 Instruction 32 KiB (x8)
  L2 Unified 1280 KiB (x8)
  L3 Unified 24576 KiB (x1)
Load Average: 4.09, 2.25, 2.03
***WARNING*** CPU scaling is enabled, the benchmark real time measurements may be noisy and will incur extra overhead.
***WARNING*** Library was built as DEBUG. Timings may be affected.
-----------------------------------------------------
Benchmark           Time             CPU   Iterations
-----------------------------------------------------
BM_Sum           2.73 ns         2.73 ns    253016984

我尝试在 google benchmarks 的 repo 上查找一些信息,尽管该 repo 本身被设置为 bazel 项目,但我没有找到有关如何在 bazel 发布模式下使用它的说明。 只写了使用CMake时使用-DCMAKE_BUILD_TYPE=Release

benchmarking bazel build-system google-benchmark bazel-cpp
1个回答
0
投票
在发布模式下构建它的选项之一是使用

--compilation_mode=opt

 构建目标,例如在本例中:

bazel run --compilation_mode=opt //benchmarks:hello-world
我还是想知道是否有更好的选择

© www.soinside.com 2019 - 2024. All rights reserved.