forked from apolukhin/course-nimble_cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
container_2.hpp
45 lines (37 loc) · 1.25 KB
/
container_2.hpp
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
#include "util.hpp"
#include <vector>
#include <deque>
#include <list>
//////////////////////////// TASK 2 ////////////////////////////
static void naive_containers_erase(benchmark::State& state, int) {
const std::size_t elements_count = state.range(0);
for (auto _ : state) {
state.PauseTiming();
std::vector<int> d;
fill_container(d, elements_count);
state.ResumeTiming();
while (!d.empty()) {
d.erase(d.begin());
}
benchmark::DoNotOptimize(d);
}
state.SetComplexityN(state.range(0));
}
static void optim_containers_erase(benchmark::State& state, int) {
const std::size_t elements_count = state.range(0);
for (auto _ : state) {
state.PauseTiming();
std::vector<int> d;
fill_container(d, elements_count);
state.ResumeTiming();
while (!d.empty()) {
// Optimize
d.erase(d.begin());
}
benchmark::DoNotOptimize(d);
}
state.SetComplexityN(state.range(0));
}
//////////////////////////// DETAIL ////////////////////////////
BENCH(naive_containers_erase, naive_containers_erase, 0)->Range(8, 8<<8)->Complexity();
BENCH(optim_containers_erase, optim_containers_erase, 0)->Range(8, 8<<8)->Complexity();