-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeque.cpp
More file actions
59 lines (50 loc) · 1.62 KB
/
Copy pathdeque.cpp
File metadata and controls
59 lines (50 loc) · 1.62 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
#include <benchmark/benchmark.h>
#include <deque>
#include <chrono>
void BM_deque_add_ints(benchmark::State &state) {
int arr[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
while (state.KeepRunning()) {
std::deque<int> ideque;
for (auto i : arr) {
ideque.push_back(i);
}
}
}
BENCHMARK(BM_deque_add_ints);
void BM_deque_copy(benchmark::State &state) {
std::deque<int> ideque = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
while (state.KeepRunning()) {
auto other = ideque;
(void)other;
}
}
BENCHMARK(BM_deque_copy);
using namespace std::chrono;
void BM_deque_insert_middle(benchmark::State &state) {
std::deque<int> ideque(2000, 0);
while (state.KeepRunning()) {
auto other = ideque;
auto begin = high_resolution_clock::now();
other.insert(std::next(other.begin(), 50), 0);
auto end = high_resolution_clock::now();
auto elapsed = duration_cast<duration<double>>(end - begin);
state.SetIterationTime(elapsed.count());
}
}
BENCHMARK(BM_deque_insert_middle)->UseManualTime();
struct Data {
int a = 0;
std::string b = "some";
};
void BM_deque_insert_middle_struct(benchmark::State &state) {
std::deque<Data> ideque(2000);
while (state.KeepRunning()) {
auto other = ideque;
auto begin = high_resolution_clock::now();
other.insert(std::next(other.begin(), 50), Data{});
auto end = high_resolution_clock::now();
auto elapsed = duration_cast<duration<double>>(end - begin);
state.SetIterationTime(elapsed.count());
}
}
BENCHMARK(BM_deque_insert_middle_struct)->UseManualTime();