1 ///////////////////////////////////////////////////////////////
2 // Copyright 2011-9 John Maddock. Distributed under the Boost
3 // Software License, Version 1.0. (See accompanying file
4 // LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt
5
6 #include "performance_test.hpp"
7
8 #ifdef TEST_MPZ
9 #include <gmp.h>
10 #endif
11 #ifdef TEST_MPFR
12 #include <mpfr.h>
13 #endif
14 #include <boost/version.hpp>
15
16 //
17 // Keys in order are:
18 // Category
19 // Operator
20 // Type
21 // Precision
22 // Time
23 //
24 std::map<std::string, std::map<std::string, std::map<std::string, std::map<int, double> > > > result_table;
25
26 unsigned bits_wanted; // for integer types
27
quickbook_results()28 void quickbook_results()
29 {
30 //
31 // Keys in order are:
32 // Category
33 // Operator
34 // Type
35 // Precision
36 // Time
37 //
38 typedef std::map<std::string, std::map<std::string, std::map<std::string, std::map<int, double> > > >::const_iterator category_iterator;
39 typedef std::map<std::string, std::map<std::string, std::map<int, double> > >::const_iterator operator_iterator;
40 typedef std::map<std::string, std::map<int, double> >::const_iterator type_iterator;
41 typedef std::map<int, double>::const_iterator precision_iterator;
42
43 for (category_iterator i = result_table.begin(); i != result_table.end(); ++i)
44 {
45 std::string cat = i->first;
46 cat[0] = (char)std::toupper((char)cat[0]);
47 std::cout << "[section:" << i->first << "_performance " << cat << " Type Perfomance]" << std::endl;
48
49 for (operator_iterator j = i->second.begin(); j != i->second.end(); ++j)
50 {
51 std::string op = j->first;
52 std::cout << "[table Operator " << op << std::endl;
53 std::cout << "[[Backend]";
54
55 for (precision_iterator k = j->second.begin()->second.begin(); k != j->second.begin()->second.end(); ++k)
56 {
57 std::cout << "[" << k->first << " Bits]";
58 }
59 std::cout << "]\n";
60
61 std::vector<double> best_times(j->second.begin()->second.size(), (std::numeric_limits<double>::max)());
62 for (unsigned m = 0; m < j->second.begin()->second.size(); ++m)
63 {
64 for (type_iterator k = j->second.begin(); k != j->second.end(); ++k)
65 {
66 if (m < k->second.size())
67 {
68 precision_iterator l = k->second.begin();
69 std::advance(l, m);
70 if (best_times[m] > l->second)
71 best_times[m] = l->second ? l->second : best_times[m];
72 }
73 }
74 }
75
76 for (type_iterator k = j->second.begin(); k != j->second.end(); ++k)
77 {
78 std::cout << "[[" << k->first << "]";
79
80 unsigned m = 0;
81 for (precision_iterator l = k->second.begin(); l != k->second.end(); ++l)
82 {
83 double rel_time = l->second / best_times[m];
84 if (rel_time == 1)
85 std::cout << "[[*" << rel_time << "]";
86 else
87 std::cout << "[" << rel_time;
88 std::cout << " (" << l->second << "s)]";
89 ++m;
90 }
91
92 std::cout << "]\n";
93 }
94
95 std::cout << "]\n";
96 }
97
98 std::cout << "[endsect]" << std::endl;
99 }
100 }
101
102 #if defined(__HAS_INCLUDE)
103 #if __has_include(<sys/utsname.h>)
104 #define HAS_UTSNAME
105 #include <sys/utsname.h>
106 #endif
107 #endif
108 #ifdef _WIN32
109 #include <windows.h>
110 #endif
111
quickbook_platform_details()112 void quickbook_platform_details()
113 {
114 std::cout << "[table:platform Platform Details\n[[Platform][";
115 #ifdef HAS_UTSNAME
116 utsname name;
117 uname(&name);
118 std::cout << name.sysname << " " << name.release << ", version " << name.version << ", " << name.machine << "]]\n";
119 #elif defined(_WIN32)
120 std::cout << "Windows ";
121 #ifdef _M_AMD64
122 std::cout << "x64";
123 #elif defined(_M_IX86)
124 std::cout << "x86";
125 #endif
126 std::cout << "]]\n";
127 #endif
128 std::cout << "[[Compiler][" << BOOST_COMPILER << "]]\n";
129 #ifdef TEST_MPZ
130 std::cout << "[[GMP][" << gmp_version << "]]\n";
131 #endif
132 #ifdef TEST_MPFR
133 std::cout << "[[MPFR][" << MPFR_VERSION << "]]\n";
134 #endif
135 std::cout << "[[Boost][" << BOOST_VERSION << "]]\n";
136 std::cout << "[[Run date][" << __DATE__ << "]]\n";
137 std::cout << "]\n\n";
138 }
139
main()140 int main()
141 {
142 quickbook_platform_details();
143
144 test01();
145 test02();
146 test03();
147 test04();
148 test05();
149 test06();
150 test07();
151 test08();
152 test09();
153 test10();
154 test11();
155 test12();
156 test13();
157 test14();
158 test15();
159 test16();
160 test17();
161 test18();
162 test19();
163 test20();
164 test21();
165 test22();
166 test23();
167 test24();
168 test25();
169 test26();
170 test27();
171 test28();
172 test29();
173 test30();
174 test31();
175 test32();
176 test33();
177 test34();
178 test35();
179 test36();
180 test37();
181 test38();
182 test39();
183 test40();
184 test41();
185 test42();
186 test43();
187 test44();
188 test45();
189 test46();
190 test47();
191 test48();
192 test49();
193 test50();
194 test51();
195
196 quickbook_results();
197 return 0;
198 }
199