-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathallocator_benchmark.cpp
More file actions
94 lines (68 loc) · 2.02 KB
/
allocator_benchmark.cpp
File metadata and controls
94 lines (68 loc) · 2.02 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//
// Created by oem on 31.05.18.
//
#include <list>
#include <benchmark/benchmark.h>
#include <tgmath.h>
#include <random>
#include "allocator.h"
template <typename Allocator>
void BM_fixed_allocator_int(benchmark::State& state) {
for (auto _: state) {
std::list<int, Allocator> test;
int limit = 1000000;
for(int i = 0; i < limit; ++i) {
test.push_back(i);
}
test.erase(test.begin());
test.erase(std::prev(test.end()));
auto iter = test.begin();
std::advance(iter, 1000);
test.erase(iter);
for(int i = 0; i < limit; ++i) {
test.push_back(i);
}
iter = test.begin();
for (int i = 0; i < 8; ++i) {
std::advance(iter, 1000);
iter = test.erase(iter);
}
for(int i = 0; i < limit; ++i) {
test.push_back(i);
}
test.clear();
}
}
template <typename Allocator>
void BM_fixed_allocator_string(benchmark::State& state) {
for (auto _: state) {
std::list<std::string, Allocator> test;
int limit = 100000;
std::string s(100, ' ');
for(int i = 0; i < limit; ++i) {
test.push_back(s);
}
test.erase(test.begin());
test.erase(std::prev(test.end()));
auto iter = test.begin();
std::advance(iter, 1000);
test.erase(iter);
for(int i = 0; i < limit; ++i) {
test.push_back(s);
}
iter = test.begin();
for (int i = 0; i < 8; ++i) {
std::advance(iter, 1000);
iter = test.erase(iter);
}
for(int i = 0; i < limit; ++i) {
test.push_back(s);
}
test.clear();
}
}
BENCHMARK_TEMPLATE(BM_fixed_allocator_int, std::allocator<int>);
BENCHMARK_TEMPLATE(BM_fixed_allocator_int, kkk::Allocator<int>);
BENCHMARK_TEMPLATE(BM_fixed_allocator_string, std::allocator<std::string>);
BENCHMARK_TEMPLATE(BM_fixed_allocator_string, kkk::Allocator<std::string>);
BENCHMARK_MAIN();