[FR] Do not necessarily print "s" or "/s" for custom counters tagged as rate

Aperta
#1,588 0 commenti 1 reazione 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@Chaturvediharsh123 ci sta già lavorando.

Dal 2/10/2026.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
55/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
cpp
Ambito
performance

Direzione di ricerca

Inizia dalla logica di formattazione delle frequenze in src/console_reporter.cc indicata dall’issue, quindi segui l’enum dei flag di Counter e il modo in cui vengono visualizzati i contatori personalizzati. La modifica è completa quando un contatore di frequenza che usa kHasNoUnit viene stampato senza un suffisso "/s" automatico, mentre gli altri contatori di frequenza mantengono la formattazione esistente.

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

Descrizione

Is your feature request related to a problem? Please describe.
I would like to have a new column in my benchmark report presenting the number of operations per dollar. I have a constant value that I know, which is the cost per second. The calculation I want in that column is given by the formula:

number_of_iterations / (cost_per_second * total_execution_time_in_seconds)

I think I can obtain the number of iterations using the iterations() function in the state object, but I couldn't find a way to recover the total execution time. The only way I found to do that calculation is by adding a new counter with 1 / cost_per_second and tag it as benchmark::Counter::kIsIterationInvariantRate

state.counters["Throughput"] = benchmark::Counter(
   1 / cost_per_second, 
   benchmark::Counter::kIsIterationInvariantRate
);

This will multiply 1 / cost_per_second by number_of_iterations / total_execution_time_in_seconds and will give me the exact value I want. However, since I'm using a kIsRate variant, it will always append "/s" to that value when I print the report in the console. This is wrong. The unit, in this case, would be "OP/$".

Describe the solution you'd like
Implement a new element in the enum kHasNoUnit and don't append the "/s" in case it is in use.

state.counters["Throughput"] = benchmark::Counter(
   1 / cost_per_second, 
   benchmark::Counter::kIsIterationInvariantRate | benchmark::Counter::kHasNoUnit
);

Describe alternatives you've considered
Another option would be to simply enable the user to define a custom unit to the counter. In this case, I would set "OP/$".

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

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.