Skip to content

Commit 54a017d

Browse files
committed
feat: add example with inlined function
1 parent 41cbb9f commit 54a017d

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

examples/google_benchmark_cmake/main.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,22 @@ static void BM_memcpy(benchmark::State &state) {
5656
delete[] src;
5757
delete[] dst;
5858
}
59-
6059
BENCHMARK(BM_memcpy)->Range(8, 8 << 10);
6160

61+
static inline int compute_sum(int x) {
62+
int sum = 0;
63+
for (int i = 0; i < x; i++) {
64+
sum += i;
65+
}
66+
return sum;
67+
}
68+
69+
static void BM_inlined_compute_sum(benchmark::State &state) {
70+
for (auto _ : state) {
71+
benchmark::DoNotOptimize(compute_sum(1024));
72+
benchmark::ClobberMemory();
73+
}
74+
}
75+
BENCHMARK(BM_inlined_compute_sum);
76+
6277
BENCHMARK_MAIN();

0 commit comments

Comments
 (0)