-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.cpp
More file actions
49 lines (41 loc) · 1.19 KB
/
main.cpp
File metadata and controls
49 lines (41 loc) · 1.19 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
#include <benchmark/benchmark.h>
#include <cstring>
#include "fixture_bench.hpp"
#include "template_bench.hpp"
template <class... Args>
void BM_Capture(benchmark::State &state, Args &&...args) {
auto args_tuple = std::make_tuple(std::move(args)...);
(void)args_tuple;
for (auto _ : state) {
}
}
BENCHMARK_CAPTURE(BM_Capture, int_string_test, 42, std::string("abc"));
BENCHMARK_CAPTURE(BM_Capture, int_test, 42, 43);
// Function to benchmark
static void BM_rand_vector(benchmark::State &state) {
std::vector<int> v;
for (auto _ : state) {
std::string empty_string;
}
}
// Register the function as a benchmark
BENCHMARK(BM_rand_vector);
// Function to benchmark with a parameter
static void BM_StringCopy(benchmark::State &state) {
std::string x = "hello";
for (auto _ : state) {
std::string copy(x);
}
}
// Register the function as a benchmark
BENCHMARK(BM_StringCopy);
static void BM_memcpy(benchmark::State &state) {
char *src = new char[state.range(0)];
char *dst = new char[state.range(0)];
memset(src, 'x', state.range(0));
for (auto _ : state) memcpy(dst, src, state.range(0));
delete[] src;
delete[] dst;
}
BENCHMARK(BM_memcpy)->Range(8, 8 << 10);
BENCHMARK_MAIN();