-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmarks.cpp
158 lines (130 loc) · 4.26 KB
/
benchmarks.cpp
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#define BENCHPRESS_FILE_OUTPUT
#include <chrono>
#include <thread>
#include <vector>
#include "benchpress_edited.hpp"
// #include "allocator.hpp"
#include "vector.hpp"
#ifndef BENCHPRESS_CONFIG_MAIN
benchpress::registration* benchpress::registration::d_this;
#endif
using std_v_std_a = std::vector<int, std::allocator<int>>;
using std_v_ctl_a = std::vector<int, ctl::Allocator<int>>;
using ctl_v_std_a = ctl::Vector<int, std::allocator<int>>;
using ctl_v_ctl_a = ctl::Vector<int, ctl::Allocator<int>>;
BENCHMARK("push_back -> std::vector && std::allocator", [](benchpress::context* ctx) {
for (auto k = 1; k < ctx->num_iterations(); ++k) {
std_v_std_a v;
for (int i = 0; i < k && i < FIXED_SIZE; ++i) {
v.push_back(i);
}
}
});
BENCHMARK("push_back -> std::vector && ctl::Allocator", [](benchpress::context* ctx) {
for (auto k = 1; k < ctx->num_iterations(); ++k) {
std_v_ctl_a v;
for (auto i = 0; i < k && i < FIXED_SIZE; ++i) {
v.push_back(i);
}
}
});
BENCHMARK("push_back -> ctl::Vector && std::allocator", [](benchpress::context* ctx) {
for (auto k = 1; k < ctx->num_iterations(); ++k) {
ctl_v_std_a v;
for (auto i = 0; i < k && i < FIXED_SIZE; ++i) {
v.push_back(i);
}
}
});
BENCHMARK("push_back -> ctl::Vector && ctl::Allocator", [](benchpress::context* ctx) {
for (auto k = 1; k < ctx->num_iterations(); ++k) {
ctl_v_ctl_a v;
for (auto i = 0; i < k && i < FIXED_SIZE; ++i) {
v.push_back(i);
}
}
});
BENCHMARK("complex -> std::vector && std::allocator", [](benchpress::context* ctx) {
for (auto k = 1; k < ctx->num_iterations(); ++k) {
std_v_std_a v;
for (auto i = 0; i < 250 * k && i < FIXED_SIZE; ++i) {
v.push_back(i);
}
for (auto i = 0; i < 150 * k && i < FIXED_SIZE; ++i) {
v.pop_back();
}
v.shrink_to_fit();
v.clear();
v.insert(v.begin(), k, 345);
v.erase(v.begin() + v.size() / 2, v.end());
}
});
BENCHMARK("complex -> std::vector && ctl::Allocator", [](benchpress::context* ctx) {
for (auto k = 1; k < ctx->num_iterations(); ++k) {
std_v_ctl_a v;
for (auto i = 0; i < 250 * k && i < FIXED_SIZE; ++i) {
v.push_back(i);
}
for (auto i = 0; i < 150 * k && i < FIXED_SIZE; ++i) {
v.pop_back();
}
v.shrink_to_fit();
v.clear();
v.insert(v.begin(), k, 345);
v.erase(v.begin() + v.size() / 2, v.end());
}
});
BENCHMARK("complex -> ctl::Vector && std::allocator", [](benchpress::context* ctx) {
for (auto k = 1; k < ctx->num_iterations(); ++k) {
ctl_v_std_a v;
for (auto i = 0; i < 250 * k && i < FIXED_SIZE; ++i) {
v.push_back(i);
}
for (auto i = 0; i < 150 * k && i < FIXED_SIZE; ++i) {
v.pop_back();
}
v.shrink_to_fit();
v.clear();
v.insert(v.begin(), k, 345);
v.erase(v.begin() + v.size() / 2, v.end());
}
});
BENCHMARK("complex -> ctl::Vector && ctl::Allocator", [](benchpress::context* ctx) {
for (auto k = 1; k < ctx->num_iterations(); ++k) {
ctl_v_ctl_a v;
for (auto i = 0; i < 250 * k && i < FIXED_SIZE; ++i) {
v.push_back(i);
}
for (auto i = 0; i < 150 * k && i < FIXED_SIZE; ++i) {
v.pop_back();
}
v.shrink_to_fit();
v.clear();
v.insert(v.begin(), k, 345);
v.erase(v.begin() + v.size() / 2, v.end());
}
});
int main(int argc, char** argv)
{
std::cout << "Benchmark started..." << std::endl;
benchpress::options bench_opts;
bench_opts.cpu(1);
float timeTaken = 0.f;
int seconds = 4;
for (auto i = 1; i <= seconds; ++i) {
std::chrono::high_resolution_clock::time_point bp_start = std::chrono::high_resolution_clock::now();
bench_opts.benchtime(i);
benchpress::out_stream << "SECTION for benchtime(" << i << ")" << std::endl;
benchpress::run_benchmarks(bench_opts);
float duration = std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::high_resolution_clock::now() - bp_start
).count() / 1000.f;
std::cout << "Processed " << i << " of " << seconds << std::endl;
benchpress::out_stream << std::endl;
benchpress::out_stream << "Time taken: " << duration << "s" << std::endl;
benchpress::out_stream << std::endl << std::endl;
timeTaken += duration;
}
std::cout << "Benchmark finished in " << timeTaken << "s" << std::endl;
return 0;
}