Skip to content

Commit 0fe9d48

Browse files
authored
Update counter.cc
1 parent 2279f2a commit 0fe9d48

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/counter.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ double Finish(Counter const& c, IterationCount iterations, double cpu_time,
2323
double num_threads) {
2424
double v = c.value;
2525
if ((c.flags & Counter::kIsRate) != 0) {
26-
v /= cpu_time;
26+
// The CPU time is the total time taken by all threads (https://github.com/google/benchmark/pull/1836)
27+
// If we used that as the denominator, we'd be calculating the rate per thread here. This is why
28+
// we have to divide the total cpu_time by the number of threads for global counters to get a global rate.
29+
//
30+
// See https://github.com/google/benchmark/issues/2080
31+
v /= (cpu_time / num_threads);
2732
}
2833
if ((c.flags & Counter::kAvgThreads) != 0) {
2934
v /= num_threads;

0 commit comments

Comments
 (0)