-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.cpp
131 lines (108 loc) · 3.16 KB
/
main.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
// Copyright (c) 2014, Ruslan Baratov
// All rights reserved.
#include <cstdlib> // EXIT_SUCCESS
#include <iostream> // std::cerr
#include "Runner.hpp"
#include "Algos.hpp"
#include "Output.ipp"
template <class Type> const char* get_name();
template <>
const char* get_name<short>() {
return "short";
}
template <>
const char* get_name<int>() {
return "int";
}
template <>
const char* get_name<long>() {
return "long";
}
template <>
const char* get_name<long long>() {
return "long long";
}
template <class Type> void run_with_type(
size_t output_size, int digit, bool have_sign
) {
using In = Input<Type>;
In input(output_size, digit, have_sign);
Output output(output_size, input);
#if !defined(NDEBUG)
std::cout << "*** DEBUG BUILD ***" << std::endl;
#endif
std::cout << "Converting " << input.values().size() << " ";
std::cout << get_name<Type>() << " with ";
if (digit == 0) {
std::cout << "ANY ";
}
else {
std::cout << digit << " ";
}
std::cout << "base-10 digits ";
if (!have_sign) {
std::cout << "(no sign) ";
}
std::cout << "to buffer " << output.size() << " bytes" << std::endl;
Runner<In, AlgoFmtFormat> algo_fmt_format(input, output, "fmt::FormatInt");
Runner<In, AlgoCppx> algo_cppx(input, output, "cppx::decimal_from");
Runner<In, AlgoBoostKarma> algo_boost_karma(input, output, "boost::spirit::karma");
std::cout << "Run tests ";
std::cout << "#1 " << std::flush;
algo_fmt_format.run();
algo_cppx.run();
algo_boost_karma.run();
std::cout << "#2 " << std::flush;
algo_fmt_format.run();
algo_cppx.run();
algo_boost_karma.run();
std::cout << "#3 " << std::flush;
algo_fmt_format.run();
algo_cppx.run();
algo_boost_karma.run();
std::cout << "#4 " << std::flush;
algo_fmt_format.run();
algo_cppx.run();
algo_boost_karma.run();
std::cout << "#5 " << std::flush;
algo_fmt_format.run();
algo_cppx.run();
algo_boost_karma.run();
std::cout << "Results: " << std::endl;
Timer::Duration algo_fmt_format_avg = algo_fmt_format.average();
Timer::Duration algo_cppx_avg = algo_cppx.average();
Timer::Duration algo_boost_karma_avg = algo_boost_karma.average();
Timer::Duration min = std::min(
{algo_fmt_format_avg, algo_cppx_avg, algo_boost_karma_avg}
);
// Output results
algo_fmt_format.output_result(min);
algo_cppx.output_result(min);
algo_boost_karma.output_result(min);
}
int main() {
try {
std::vector<size_t> output_size_variants{30, 300, 4096};
std::vector<int> digit_variants{0, 1, 2, 4, 10};
std::vector<bool> sign_variants{true, false};
for (auto output_size: output_size_variants) {
for (auto digit: digit_variants) {
for (auto sign: sign_variants) {
// run_with_type<short>(output_size, digit, sign);
run_with_type<int>(output_size, digit, sign);
// run_with_type<long>(output_size, digit, sign);
run_with_type<long long>(output_size, digit, sign);
}
}
}
return EXIT_SUCCESS;
}
catch (std::exception& exc) {
std::cerr << exc.what() << std::endl;
return EXIT_FAILURE;
}
catch (...) {
std::cerr << "Unknown exception" << std::endl;
return EXIT_FAILURE;
}
}