I use google benchmark to test two C++ functions. One runs for ~630,000,000 ns and one runs for ~1,000,000,000 ns. But both only run one iteration. How can I force the benchmark to run more iterations? I would like it to run at least 10 times.
Asked
Active
Viewed 1,359 times
2 Answers
6
You can actually do
BENCHMARK(YourBenchmark)->Iterations(100); // will run for 100 iterations
Note that this will run the benchmark exactly 100 times. I couldn't find a way for it to run at least a number of times

McLeary
- 1,231
- 2
- 13
- 21
-
1Cannot believe I miss this. Maybe I was reading an older document or so? Good to know this, and thank you! – Harper Jan 28 '21 at 17:46
-
1This should be the accepted answer I think. – Julien Marrec Oct 07 '21 at 10:58
4
For those who encounter similar problems:
There is no way to directly control the number of iterations for a benchmark. Instead, one can use benchmark_min_time to indirectly configure the number of iterations a benchmark runs. A simple way to do this is:
BENCHMARK(YourBenchmark)->MinTime(10); // 10 seconds

Harper
- 1,794
- 14
- 31