Skip to content

Commit 15b5d12

Browse files
committed
feat: add bench with PauseTiming
1 parent 7317f26 commit 15b5d12

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-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: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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_setup_teardown(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+
// IMPORTANT: Use fixed iterations, otherwise we'll run for 10+ minutes
29+
BENCHMARK(BM_large_setup_teardown)->Iterations(100);
30+
31+
static void BM_large_setup(benchmark::State& state) {
32+
for (auto _ : state) {
33+
state.PauseTiming();
34+
benchmark::DoNotOptimize(expensive_operation());
35+
state.ResumeTiming();
36+
37+
benchmark::DoNotOptimize(actual_work());
38+
}
39+
}
40+
BENCHMARK(BM_large_setup);

0 commit comments

Comments
 (0)