Harper
Harper

Reputation: 1954

How to force google benchmark to run multiple iterations?

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.

Upvotes: 3

Views: 2300

Answers (2)

McLeary
McLeary

Reputation: 1271

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

Upvotes: 7

Harper
Harper

Reputation: 1954

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

Upvotes: 5

Related Questions