I am benchmarking some functions in our software using the Google-benchmark. Let us say the function signature is something like below. The return type can be any other derived data type.
std::map<uint32_t, bool> func(Obj& o1, Obj& o2);
The benchmark function looks something like this.
static void BM_Func(benchmark::State& state) {
// Prepare the objects o1 and o2
for (auto _ : state)
func(Obj& o1, Obj& o2);
}
BENCHMARK(BM_Func);
BENCHMARK_MAIN();
Now, the code compiles and I am able to collect the benchmark results. However, I have below questions.
- What happens to the return values? Should I be bothered at all if I am not using these values anywhere again in the benchmark function?
- Should I call the function instead like this
benchmark::DoNotOptimize( func(Obj& o1, Obj& o2) );
to avoid optimization? I do not really understand when to call the function withbenchmark::DoNotOptimize