-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtemplate_bench.hpp
More file actions
60 lines (51 loc) · 1.4 KB
/
template_bench.hpp
File metadata and controls
60 lines (51 loc) · 1.4 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#ifndef TEMPLATE_BENCH_HPP
#define TEMPLATE_BENCH_HPP
#include <benchmark/benchmark.h>
#include <cstring>
#include <string>
namespace test {
template <class T> void BM_Template(benchmark::State &state) {
std::vector<T> v;
for (auto _ : state) {
v.push_back(T());
benchmark::DoNotOptimize(v);
benchmark::ClobberMemory();
}
}
BENCHMARK_TEMPLATE(BM_Template, int);
BENCHMARK_TEMPLATE(BM_Template, std::string);
} // namespace test
//
//
template <typename T> void BM_Template1(benchmark::State &state) {
T val = T();
for (auto _ : state) {
benchmark::DoNotOptimize(val++);
}
}
BENCHMARK_TEMPLATE1(BM_Template1, int);
//
//
template <typename T, typename U> void BM_Template2(benchmark::State &state) {
T t = T();
U u = U();
for (auto _ : state) {
benchmark::DoNotOptimize(t + u);
}
}
BENCHMARK_TEMPLATE2(BM_Template2, int, double);
//
//
template <typename T, class... ExtraArgs>
void BM_Template1_Capture(benchmark::State &state, ExtraArgs &&...extra_args) {
auto args_tuple = std::make_tuple(std::move(extra_args)...);
for (auto _ : state) {
benchmark::DoNotOptimize(args_tuple);
benchmark::ClobberMemory();
}
}
BENCHMARK_TEMPLATE1_CAPTURE(BM_Template1_Capture, void, int_string_test, 42,
std::string("abc"));
BENCHMARK_TEMPLATE2_CAPTURE(BM_Template1_Capture, int, double, two_type_test,
42, std::string("abc"));
#endif