forked from apolukhin/course-nimble_cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
container_3.hpp
37 lines (29 loc) · 974 Bytes
/
container_3.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
#include "util.hpp"
#include <vector>
#include <deque>
#include <list>
//////////////////////////// TASK 3 ////////////////////////////
static void naive_insertion(benchmark::State& state, int) {
const std::size_t elements_count = state.range(0);
for (auto _ : state) {
std::vector<int> d;
for (unsigned i = 0; i < elements_count; ++i) {
d.push_back(i);
}
benchmark::DoNotOptimize(d);
}
}
static void optim_insertion(benchmark::State& state, int) {
const std::size_t elements_count = state.range(0);
for (auto _ : state) {
// TASK: Improve
std::vector<int> d;
for (unsigned i = 0; i < elements_count; ++i) {
d.push_back(i);
}
benchmark::DoNotOptimize(d);
}
}
//////////////////////////// DETAIL ////////////////////////////
BENCH(naive_insertion, naive_insertion, 0)->Range(8, 8<<10);
BENCH(optim_insertion, optim_insertion, 0)->Range(8, 8<<10);