martinus / nanobench

Simple, fast, accurate single-header microbenchmarking functionality for C++11/14/17/20
https://nanobench.ankerl.com
MIT License
1.44k stars 83 forks source link

setup support #81

Closed screwzm closed 1 year ago

screwzm commented 1 year ago

I am wondering whether superb nanobench supports setup that is not part of the benchmar? For my cases, I would like to setup some context before running the actual part that needs to be benchmarked.

Basically I am looking for something like this:

int main() {

ankerl::nanobench::Bench().run("some double ops", [&] {
   // stop timing
   setup()
   // resume timing

  actual_code_to_banchmark_based_on_the_setup();

});

}

screwzm commented 1 year ago

Google benchmark is bad since the state.PauseTiming/ResumeTiming have heavy overhead themselves, hence cuase the result not usable.

martinus commented 1 year ago

no because this can't be done well. Create two benchmarks: one with setup, another one with setup & actual benchmark code, and subtract the first.

martinus commented 1 year ago

Closed in favor of #86