Can I calculate throughput via google benchmark library in C++

407 Views Asked by At

I want to measure how many times C++ function will be executed per N seconds, is there a way to do that via google benchmark? Maybe using some lambda for ComputeStatistics function?

If there is no way to do it via google benchmark: are there any other ways of measuring throughput?

2

There are 2 best solutions below

0
blonded04 On BEST ANSWER

Actually, the easiest way is to use ->MinTime(seconds) for each of your benchmarks you want to calculate throughput for, and then simply taking Iterations from each of the benchmarks.

1
Cory Kramer On

The throughput is reported in units of items/s https://github.com/google/benchmark/blob/main/docs/user_guide.md#output-formats

Benchmark                Time(ns)    CPU(ns) Iterations
-------------------------------------------------------
BM_SetInsert/1024/1         28928      29349      23853  133.097kB/s   33.2742k items/s
BM_SetInsert/1024/8         32065      32913      21375  949.487kB/s   237.372k items/s
BM_SetInsert/1024/10        33157      33648      21431  1.13369MB/s   290.225k items/s

So to directly answer your question

I want to measure how many times C++ function will be executed per N seconds

you would take this items/s and multiply by N seconds, that would give you approximately the number of items processed in N seconds.