forked from benchmark-action/github-action-benchmark
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbench.cpp
More file actions
34 lines (29 loc) · 735 Bytes
/
bench.cpp
File metadata and controls
34 lines (29 loc) · 735 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "./fib.hpp"
#include "benchmark/benchmark.h"
static void fib_10(benchmark::State &state) {
for (auto _ : state) {
// Suppress optimization otherwise this line is removed by DCE
int i = 10;
benchmark::DoNotOptimize(i);
benchmark::DoNotOptimize(fib(i));
}
}
static void fib_20(benchmark::State &state) {
for (auto _ : state) {
int i = 20;
benchmark::DoNotOptimize(i);
benchmark::DoNotOptimize(fib(i));
}
}
static void fib_30(benchmark::State &state) {
for (auto _ : state) {
int i = 30;
benchmark::DoNotOptimize(i);
benchmark::DoNotOptimize(fib(i));
}
}
// Register the function as a benchmark
BENCHMARK(fib_10);
BENCHMARK(fib_20);
// Run the benchmark
BENCHMARK_MAIN();