Skip to content

Commit 3827adf

Browse files
committed
Fix minimum benchmark time with multiple threads
Closes #2117
1 parent 4ed29ae commit 3827adf

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/benchmark_runner.cc

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,7 @@ BenchmarkReporter::Run CreateRunReport(
123123
: 0;
124124
}
125125

126-
// The CPU time is the total time taken by all thread. If we used that as
127-
// the denominator, we'd be calculating the rate per thread here. This is
128-
// why we have to divide the total cpu_time by the number of threads for
129-
// global counters to get a global rate.
130-
const double thread_seconds = seconds / b.threads();
131-
internal::Finish(&report.counters, results.iterations, thread_seconds,
126+
internal::Finish(&report.counters, results.iterations, seconds,
132127
b.threads());
133128
}
134129
return report;
@@ -361,6 +356,9 @@ BenchmarkRunner::IterationResults BenchmarkRunner::DoNIterations() {
361356
} else if (b.use_real_time()) {
362357
i.seconds = i.results.real_time_used;
363358
}
359+
// The time is the sum over all threads, we want each of them to run the
360+
// specificed minimum time.
361+
i.seconds /= b.threads();
364362

365363
return i;
366364
}

0 commit comments

Comments
 (0)