2

I am running some performance tests using google benchmark API. I use state.PauseTiming() and state.ResumeTiming() to avoid unnecessary code segments runs through perf path. I have attached the sample code below

 while (state.KeepRunning()) {
    state.PauseTiming();
    state.ResumeTiming();
    state.PauseTiming();
    state.ResumeTiming();
}

Those functions itself took 323ns for 2 pauses and resumes.

hiRun on (16 X 3196.36 MHz CPU s)
2019-06-19 11:21:06
---------------------------------------------------------------
Benchmark                        Time           CPU Iterations
---------------------------------------------------------------
Benchmark_Test1                 323 ns        324 ns    2158319

It this a bug in google benchmark API or are there any workarounds for this?

Kethiri Sundar
  • 480
  • 2
  • 12
  • What OS / compiler / options? What hardware (CPU model or at least ISA & microarchitecture)? – Peter Cordes Jun 19 '19 at 23:14
  • It is a suse linux sp3 machine with 16 cpu cores running in 3.2 GHz – Kethiri Sundar Jun 20 '19 at 01:39
  • But what kind of CPU cores? Intel Skylake-X? Woodcrest? AMD Ryzen? POWER 9? AArch64? Single-socket or dual-socket? Bare metal or inside a hypervisor VM? And I don't know what version of gcc your SUSE install is using, and you haven't mentioned compiler options (like `gcc -O3 -march=native` vs. un-optimized.) – Peter Cordes Jun 20 '19 at 01:43

1 Answers1

3

I had a similar use case and I noticed that the pause and resume has a lot of overhead, this is mentioned in their docs as well.

The workaround for this is another feature of Google Benchmarks. Manually measure the part of the code you want running time for inside the for loop. You can do this using manual timers (https://github.com/google/benchmark#cpu-timers).

You take chrono timestamps before and after the code segment for which you want running times and then you you set it to the state on each iterating using SetIterationTime.

When you call this test you need to add a ->UseManualTime();

Rahul Ravindran
  • 452
  • 3
  • 12