File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change 11#include < benchmark/benchmark.h>
22#include < prometheus/registry.h>
33
4+ static void BM_Counter_IncrementBaseline (benchmark::State& state) {
5+ struct {
6+ void Increment () { v += 1.0 ; }
7+ double v;
8+ } counter;
9+
10+ for (auto _ : state) {
11+ counter.Increment ();
12+ }
13+ benchmark::DoNotOptimize (counter.v );
14+ }
15+ BENCHMARK (BM_Counter_IncrementBaseline);
16+
417static void BM_Counter_Increment (benchmark::State& state) {
518 using prometheus::BuildCounter;
619 using prometheus::Counter;
@@ -10,9 +23,10 @@ static void BM_Counter_Increment(benchmark::State& state) {
1023 BuildCounter ().Name (" benchmark_counter" ).Help (" " ).Register (registry);
1124 auto & counter = counter_family.Add ({});
1225
13- while ( state. KeepRunning () ) {
26+ for ( auto _ : state) {
1427 counter.Increment ();
1528 }
29+ benchmark::DoNotOptimize (counter.Value ());
1630}
1731BENCHMARK (BM_Counter_Increment);
1832
@@ -28,6 +42,7 @@ BENCHMARK_F(BM_Counter, ConcurrentIncrement)
2842 for (auto _ : state) {
2943 counter.Increment ();
3044 }
45+ benchmark::DoNotOptimize (counter.Value ());
3146}
3247
3348static void BM_Counter_Collect (benchmark::State& state) {
You can’t perform that action at this time.
0 commit comments