[BUG] Minimum benchmark time with multiple threads

Aperta
#2,117 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@hahnjo ci sta già lavorando.

Dal 30/1/2026.

  • #2118 di @hahnjo — aperta
  • #2256 di @devtejasx — chiusa senza merge

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
cpp
Ambito
performance

Direzione di ricerca

Inizia dalla gestione di --benchmark_min_time per i benchmark ThreadRange e dal comportamento di UseRealTime descritto nell’issue. Esegui il riproduttore C++ fornito con --benchmark_min_time=1s e confronta i risultati con un singolo thread e con otto thread. Il lavoro è completato quando ogni benchmark impiega il tempo minimo per thread e il numero di iterazioni aumenta adeguatamente con l’aumentare dei thread.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Describe the bug
https://github.com/google/benchmark/pull/1836 fixed https://github.com/google/benchmark/issues/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>

static void BM_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();

The output is somewhat expected:

---------------------------------------------------------------------
Benchmark                           Time             CPU   Iterations
---------------------------------------------------------------------
BM_MultiThreaded/threads:1        275 ns          274 ns      2585850
BM_MultiThreaded/threads:2        273 ns          272 ns      2259184
BM_MultiThreaded/threads:4        279 ns          278 ns      2449204
BM_MultiThreaded/threads:8        308 ns          307 ns      2148808

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) https://github.com/google/benchmark/pull/1836.

Expected behavior
Each benchmark should spend the minimum time (per thread).

Lingua principale
C++
Stelle
10.5k
Fork
1.8k
Merge medio
1g 17h
PR unite (30g)
30

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di google/benchmark

Tutte le issue di google/benchmark

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.