-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbench_pod.cpp
40 lines (33 loc) · 863 Bytes
/
bench_pod.cpp
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
35
36
37
38
39
40
#include <benchmark/benchmark.h>
double byRef(const double& d) {
double x = d;
x += 1.0;
return x;
}
double byVal(double d) {
d += 1.0;
return d;
}
static void BM_ByRef(benchmark::State& state) {
double d = 10.0;
for (auto _ : state) {
for (auto i = 0; i <= state.range(0); ++i) {
double x = byRef(d);
benchmark::DoNotOptimize(x);
}
}
state.SetComplexityN(state.range(0));
}
static void BM_ByVal(benchmark::State& state) {
double d = 10.0;
for (auto _ : state) {
for (auto i = 0; i <= state.range(0); ++i) {
double x = byVal(d);
benchmark::DoNotOptimize(x);
}
}
state.SetComplexityN(state.range(0));
}
// Register the function as a benchmark
BENCHMARK(BM_ByRef)->RangeMultiplier(2)->Range(8, 8 << 10)->Complexity();
BENCHMARK(BM_ByVal)->RangeMultiplier(2)->Range(8, 8 << 10)->Complexity();