From 3827adf7b69593cbf092dcf0c2bb40e4f70a0a32 Mon Sep 17 00:00:00 2001 From: Jonas Hahnfeld Date: Fri, 30 Jan 2026 17:55:46 +0100 Subject: [PATCH] Fix minimum benchmark time with multiple threads Closes #2117 --- src/benchmark_runner.cc | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/benchmark_runner.cc b/src/benchmark_runner.cc index fb688672a..94c86e264 100644 --- a/src/benchmark_runner.cc +++ b/src/benchmark_runner.cc @@ -123,12 +123,7 @@ BenchmarkReporter::Run CreateRunReport( : 0; } - // The CPU time is the total time taken by all thread. If we used that as - // the denominator, we'd be calculating the rate per thread here. This is - // why we have to divide the total cpu_time by the number of threads for - // global counters to get a global rate. - const double thread_seconds = seconds / b.threads(); - internal::Finish(&report.counters, results.iterations, thread_seconds, + internal::Finish(&report.counters, results.iterations, seconds, b.threads()); } return report; @@ -361,6 +356,9 @@ BenchmarkRunner::IterationResults BenchmarkRunner::DoNIterations() { } else if (b.use_real_time()) { i.seconds = i.results.real_time_used; } + // The time is the sum over all threads, we want each of them to run the + // specificed minimum time. + i.seconds /= b.threads(); return i; }