google / benchmark

A microbenchmark support library
Apache License 2.0
8.83k stars 1.6k forks source link

[FR] Add possibility to start iteration in timing-off state. #1811

Open exposedcranium opened 1 month ago

exposedcranium commented 1 month ago

A common pattern I am using in my benchmarking code is:

for (auto _ : state) {
    state.PauseTiming();
    /* Generate some data for this iteration, or cleanup from the previous */
    state.ResumeTiming();

    /* Do some work */
}

This seems a little unpleasant because timing is starting when entering the loop body and immediately being paused. What I would like instead is something like:

for (auto _ : state.with_paused_timing()) {
    /* Generate some data for this iteration, or cleanup from the previous */
    state.ResumeTiming();

    /* Do some work */
}
dmah42 commented 1 month ago

would this do exactly the same under the hood, just not as explicitly?