I am using benchmark::RegisterBenchmark
for benchmarking my code.
For simple example I have :
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 function is doing :
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);
I want to calling my benchmark function multiple times from fun() with some extra arguments. I have replaced benchmark function with factorial for simplicity right now.
With this, time reported is always 0. What am I missing here?
Another thing is, if i do not write for (auto _ : state)
it throws run-time error and exits. The number of iterations reported are always 1000000000.