-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmarking.cpp
More file actions
41 lines (33 loc) · 1.06 KB
/
Copy pathbenchmarking.cpp
File metadata and controls
41 lines (33 loc) · 1.06 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
#include <benchmark/benchmark.h>
#include "algos.cpp"
static void BM_linear_search(benchmark::State& state)
{
// The setup code is not measured
const auto num = state.range(0);
const auto test_vect = generate_vector(num);
// Only code insde this loop is measured
for( auto _ : state )
{
benchmark::DoNotOptimize( linear_search(test_vect, num) );
}
state.SetComplexityN(num);
}
// Register benchmarking function
BENCHMARK(BM_linear_search) ->RangeMultiplier(2)
->Range(16, 8'192)
->Complexity();
static void BM_binary_search(benchmark::State& state)
{
const auto num = state.range(0);
const auto test_vect = generate_vector(num);
for( auto _ : state )
{
benchmark::DoNotOptimize( binary_search(test_vect, num) );
}
state.SetComplexityN(num);
}
BENCHMARK(BM_binary_search) ->RangeMultiplier(2)
->Range(16, 8'192)
->Complexity();
// Run all registered benchmarks
BENCHMARK_MAIN();