Skip to content

KeepRunningBatch() benchmarks are silently not measured #54

Description

@chfast

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions