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 1
1
#include < benchmark/benchmark.h>
2
2
#include < prometheus/registry.h>
3
3
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
+
4
17
static void BM_Counter_Increment (benchmark::State& state) {
5
18
using prometheus::BuildCounter;
6
19
using prometheus::Counter;
@@ -10,9 +23,10 @@ static void BM_Counter_Increment(benchmark::State& state) {
10
23
BuildCounter ().Name (" benchmark_counter" ).Help (" " ).Register (registry);
11
24
auto & counter = counter_family.Add ({});
12
25
13
- while ( state. KeepRunning () ) {
26
+ for ( auto _ : state) {
14
27
counter.Increment ();
15
28
}
29
+ benchmark::DoNotOptimize (counter.Value ());
16
30
}
17
31
BENCHMARK (BM_Counter_Increment);
18
32
@@ -28,6 +42,7 @@ BENCHMARK_F(BM_Counter, ConcurrentIncrement)
28
42
for (auto _ : state) {
29
43
counter.Increment ();
30
44
}
45
+ benchmark::DoNotOptimize (counter.Value ());
31
46
}
32
47
33
48
static void BM_Counter_Collect (benchmark::State& state) {
You can’t perform that action at this time.
0 commit comments