Benchmarks looping with while (state.KeepRunningBatch(n)) instead of the range-based for (auto _ : state) execute normally but are never measured: no Measured: line is printed for them, and a run containing only such benchmarks ends with ⚠ No benchmarks were found in the run, which makes the loss easy to miss. The instrumentation hooks are attached to the StateIterator paths only (start_benchmark() and end_benchmark() at google_benchmark/include/benchmark/benchmark.h:1101 and :1082), while State::KeepRunningInternal() at :1014, which both KeepRunning() and KeepRunningBatch() go through, has none — although both paths do call StartKeepRunning() and FinishKeepRunning(), so hooking those instead would cover the two loop styles at once. Seen with codspeed-cpp v2.4.0 and codspeed-runner 5.0.2 in simulation mode.
static void bench_batch(benchmark::State& state)
{
while (state.KeepRunningBatch(10))
for (int i = 0; i < 10; ++i)
benchmark::DoNotOptimize(work());
}
BENCHMARK(bench_batch); // executed, never reported
Benchmarks looping with
while (state.KeepRunningBatch(n))instead of the range-basedfor (auto _ : state)execute normally but are never measured: noMeasured:line is printed for them, and a run containing only such benchmarks ends with⚠ No benchmarks were found in the run, which makes the loss easy to miss. The instrumentation hooks are attached to theStateIteratorpaths only (start_benchmark()andend_benchmark()atgoogle_benchmark/include/benchmark/benchmark.h:1101and:1082), whileState::KeepRunningInternal()at:1014, which bothKeepRunning()andKeepRunningBatch()go through, has none — although both paths do callStartKeepRunning()andFinishKeepRunning(), so hooking those instead would cover the two loop styles at once. Seen with codspeed-cpp v2.4.0 and codspeed-runner 5.0.2 in simulation mode.