Skip to content

Commit

Permalink
Add increment benchmark as baseline
Browse files Browse the repository at this point in the history
  • Loading branch information
jerryct committed Nov 1, 2018
1 parent 92c67f2 commit bbc6360
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion core/benchmarks/counter_bench.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
#include <benchmark/benchmark.h>
#include <prometheus/registry.h>

static void BM_Counter_IncrementBaseline(benchmark::State& state) {
struct {
void Increment() { v += 1.0; }
double v;
} counter;

for (auto _ : state) {
counter.Increment();
}
benchmark::DoNotOptimize(counter.v);
}
BENCHMARK(BM_Counter_IncrementBaseline);

static void BM_Counter_Increment(benchmark::State& state) {
using prometheus::BuildCounter;
using prometheus::Counter;
Expand All @@ -10,9 +23,10 @@ static void BM_Counter_Increment(benchmark::State& state) {
BuildCounter().Name("benchmark_counter").Help("").Register(registry);
auto& counter = counter_family.Add({});

while (state.KeepRunning()) {
for (auto _ : state) {
counter.Increment();
}
benchmark::DoNotOptimize(counter.Value());
}
BENCHMARK(BM_Counter_Increment);

Expand All @@ -28,6 +42,7 @@ BENCHMARK_F(BM_Counter, ConcurrentIncrement)
for (auto _ : state) {
counter.Increment();
}
benchmark::DoNotOptimize(counter.Value());
}

static void BM_Counter_Collect(benchmark::State& state) {
Expand Down

0 comments on commit bbc6360

Please sign in to comment.