-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathallocator_test.cpp
154 lines (141 loc) · 5.36 KB
/
allocator_test.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
// Copyright (c) 2020-2021 Gregor Daiß
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#include "../include/buffer_manager.hpp"
#ifdef CPPUDDLE_HAVE_HPX
#include <hpx/hpx_init.hpp>
#endif
#include <boost/program_options.hpp>
#include <cassert>
#include <chrono>
#include <cstdio>
#include <fstream>
#include <iostream>
#include <string>
#include <typeinfo>
#ifdef CPPUDDLE_HAVE_HPX
int hpx_main(int argc, char *argv[]) {
#else
int main(int argc, char *argv[]) {
#endif
size_t array_size = 500000;
size_t passes = 10000;
std::string filename{};
try {
boost::program_options::options_description desc{"Options"};
desc.add_options()("help", "Help screen")(
"arraysize",
boost::program_options::value<size_t>(&array_size)
->default_value(5000000),
"Size of the buffers")(
"passes",
boost::program_options::value<size_t>(&passes)->default_value(200),
"Sets the number of repetitions")(
"outputfile",
boost::program_options::value<std::string>(&filename)->default_value(
""),
"Redirect stdout/stderr to this file");
boost::program_options::variables_map vm;
boost::program_options::parsed_options options =
parse_command_line(argc, argv, desc);
boost::program_options::store(options, vm);
boost::program_options::notify(vm);
if (vm.count("help") == 0u) {
std::cout << "Running with parameters:" << std::endl
<< " --arraysize = " << array_size << std::endl
<< " --passes = " << passes << std::endl;
} else {
std::cout << desc << std::endl;
return EXIT_SUCCESS;
}
} catch (const boost::program_options::error &ex) {
std::cerr << "CLI argument problem found: " << ex.what() << '\n';
}
if (!filename.empty()) {
freopen(filename.c_str(), "w", stdout); // NOLINT
freopen(filename.c_str(), "w", stderr); // NOLINT
}
assert(passes >= 1); // NOLINT
assert(array_size >= 1); // NOLINT
size_t aggressive_duration = 0;
size_t recycle_duration = 0;
size_t default_duration = 0;
// Aggressive recycle Test:
{
std::cout << "\nStarting run with aggressive recycle allocator: " << std::endl;
for (size_t pass = 0; pass < passes; pass++) {
auto begin = std::chrono::high_resolution_clock::now();
std::vector<double, recycler::aggressive_recycle_std<double>> test1(
array_size, double{});
auto end = std::chrono::high_resolution_clock::now();
aggressive_duration +=
std::chrono::duration_cast<std::chrono::milliseconds>(end - begin)
.count();
// Print last element - Causes the compiler to not optimize out the entire loop
std::cout << test1[array_size - 1] << " ";
}
std::cout << "\n\n==> Aggressive recycle allocation test took "
<< aggressive_duration << "ms" << std::endl;
}
recycler::print_performance_counters();
recycler::force_cleanup(); // Cleanup all buffers and the managers for better
// comparison
// Recycle Test:
{
std::cout << "\nStarting run with recycle allocator: " << std::endl;
for (size_t pass = 0; pass < passes; pass++) {
auto begin = std::chrono::high_resolution_clock::now();
std::vector<double, recycler::recycle_std<double>> test1(array_size, double{});
auto end = std::chrono::high_resolution_clock::now();
recycle_duration +=
std::chrono::duration_cast<std::chrono::milliseconds>(end - begin)
.count();
// Print last element - Causes the compiler to not optimize out the entire loop
std::cout << test1[array_size - 1] << " ";
}
std::cout << "\n\n==> Recycle allocation test took " << recycle_duration
<< "ms" << std::endl;
}
recycler::print_performance_counters();
recycler::force_cleanup(); // Cleanup all buffers and the managers for better
// comparison
// Same test using std::allocator:
{
std::cout << "\nStarting run with std::allocator: " << std::endl;
for (size_t pass = 0; pass < passes; pass++) {
auto begin = std::chrono::high_resolution_clock::now();
std::vector<double> test2(array_size, double{});
auto end = std::chrono::high_resolution_clock::now();
default_duration +=
std::chrono::duration_cast<std::chrono::milliseconds>(end - begin)
.count();
// Print last element - Causes the compiler to not optimize out the entire loop
std::cout << test2[array_size - 1] << " ";
}
std::cout << "\n\n==> Non-recycle allocation test took " << default_duration
<< "ms" << std::endl;
}
if (aggressive_duration < recycle_duration) {
std::cout << "Test information: Aggressive recycler was faster than normal "
"recycler!"
<< std::endl;
}
if (aggressive_duration < default_duration) {
std::cout << "Test information: Aggressive recycler was faster than default allocator!"
<< std::endl;
}
recycler::print_performance_counters();
#ifdef CPPUDDLE_HAVE_HPX
return hpx::finalize();
#else
return EXIT_SUCCESS;
#endif
}
#ifdef CPPUDDLE_HAVE_HPX
int main(int argc, char *argv[]) {
hpx::init_params p;
p.cfg = {"hpx.commandline.allow_unknown=1"};
return hpx::init(argc, argv, p);
}
#endif