Skip to content

Commit 184c4ea

Browse files
committed
feat: add bench with PauseTiming
1 parent 4a4e71b commit 184c4ea

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../google_benchmark_cmake/pause_timing_bench.hpp

examples/google_benchmark_cmake/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "fibonacci_bench.hpp"
66
#include "fixture_bench.hpp"
77
#include "multithread_bench.hpp"
8+
#include "pause_timing_bench.hpp"
89
#include "sleep_bench.hpp"
910
#include "template_bench.hpp"
1011

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#pragma once
2+
3+
#include <benchmark/benchmark.h>
4+
5+
#include <chrono>
6+
#include <thread>
7+
8+
#include "helper.hpp"
9+
10+
NOINLINE static uint64_t actual_work() {
11+
std::this_thread::sleep_for(std::chrono::milliseconds(1));
12+
return 42;
13+
}
14+
15+
static void BM_large_drop(benchmark::State& state) {
16+
for (auto _ : state) {
17+
state.PauseTiming();
18+
benchmark::DoNotOptimize(expensive_operation());
19+
state.ResumeTiming();
20+
21+
benchmark::DoNotOptimize(actual_work());
22+
23+
state.PauseTiming();
24+
benchmark::DoNotOptimize(expensive_operation());
25+
state.ResumeTiming();
26+
}
27+
}
28+
BENCHMARK(BM_large_drop);
29+
30+
static void BM_large_setup(benchmark::State& state) {
31+
for (auto _ : state) {
32+
state.PauseTiming();
33+
benchmark::DoNotOptimize(expensive_operation());
34+
state.ResumeTiming();
35+
36+
benchmark::DoNotOptimize(actual_work());
37+
}
38+
}
39+
BENCHMARK(BM_large_setup);

0 commit comments

Comments
 (0)