Google针对CPU的基准测试报告时间不正确

时间:2019-02-21 18:49:10

标签: c++ google-api benchmarking google-benchmark

我正在使用benchmark::RegisterBenchmark来对我的代码进行基准测试。 对于简单的例子,我有:

static void BM_Factorial(benchmark::State& state) {
  std::string x = "hello";
  for (auto _ : state) {
    uint64_t fact = 1;
    for(int i=4; i< 100000; i++)
        benchmark::DoNotOptimize(fact *= i);
  }
}

void fun(){
  // Call this multiple times
  benchmark::RegisterBenchmark("timer ", &BM_Factorial);
  // do some work
  benchmark::RunSpecifiedBenchmarks();
}

Init函数正在执行:

 int dummy = 4;
  std::string arg0 = "--help";
  std::string arg1 = "--benchmark_report_aggregates_only=true";
  std::string arg2 = "--benchmark_display_aggregates_only=true";
  std::string arg3 = "--benchmark_repetitions=10000";
  char *args[4] = {
      const_cast<char *>(arg0.c_str()), const_cast<char *>(arg1.c_str()),
      const_cast<char *>(arg2.c_str()), const_cast<char *>(arg3.c_str())};
  benchmark::Initialize(&dummy, args);

我想使用一些额外的参数从fun()多次调用我的基准函数。为了简单起见,我现在已经将阶乘函数替换为阶乘。 这样,报告的时间始终为0。我在这里错过了什么? 另一件事是,如果我不写for (auto _ : state),则会抛出运行时错误并退出。报告的迭代次数始终为1000000000。

0 个答案:

没有答案