You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] Minimum benchmark time with multiple threads #2117
Describe the bug #1836 fixed #1834 and now the reported output makes more sense. However, the minimum benchmark time doesn't seem to be respected.
System
Arch Linux, GCC 15.2.1, benchmark 1.9.5-1
To reproduce
Consider
#include<benchmark/benchmark.h>staticvoidBM_MultiThreaded(benchmark::State& state) {
int a = 0;
for (auto _ : state) {
for (int i = 0; i < 1000; i++) {
benchmark::DoNotOptimize(a++);
}
}
}
BENCHMARK(BM_MultiThreaded)->ThreadRange(1, 8);
BENCHMARK_MAIN();
However, notice that the number of iterations stays constant - it should increase as more threads are used to run the iterations. For example:
$ /usr/bin/time -v ./benchmark-multithreaded --benchmark_min_time=1s --benchmark_filter=threads:8
[...]
User time (seconds): 1.72
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.25
With previous versions of benchmark, this could be fixed with UseRealTime() but that doesn't seem to work anymore since (probably) #1836.
Expected behavior
Each benchmark should spend the minimum time (per thread).
and each benchmark is run for at least one second if I ask for it:
$ /usr/bin/time -v ./benchmark-multithreaded --benchmark_min_time=1s --benchmark_filter=threads:8
[...]
User time (seconds): 13.40
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:01.76
Activity
Fix minimum benchmark time with multiple threads
dmah42 commentedon Jan 30, 2026
what does the same table look like after your fix?
hahnjo commentedon Jan 30, 2026
With the change in #2118, the output is
and each benchmark is run for at least one second if I ask for it:
Fix minimum benchmark time with multiple threads
Respect min_time per thread in multi-threaded benchmarks (google#2117)