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 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
|
///////////////////////////////////////////////////////////////
// Copyright John Maddock 2019.
// Copyright Christopher Kormanyos 2021 - 2025.
// Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt
// This version of "performance_test_df.cpp" is based almost entirely on
// the original "performance_test.cpp". But it has been specifically
// adapted to test various backends in small precision ranges in order
// to check the performance comparison with cpp_double_double.
#include <boost/config.hpp>
#if !defined(TEST_CPP_DOUBLE_FLOAT)
#define TEST_CPP_DOUBLE_FLOAT
#endif
#if !defined(TEST_CPP_BIN_FLOAT)
#define TEST_CPP_BIN_FLOAT
#endif
#if !defined(TEST_CPP_DEC_FLOAT)
#define TEST_CPP_DEC_FLOAT
#endif
#if defined(BOOST_HAS_FLOAT128)
#if !defined(TEST_FLOAT128)
#define TEST_FLOAT128
#endif
#endif
#include <boost/version.hpp>
#if defined(TEST_CPP_DOUBLE_FLOAT)
#include <boost/multiprecision/cpp_double_fp.hpp>
#endif
#if defined(TEST_CPP_BIN_FLOAT)
#include <boost/multiprecision/cpp_bin_float.hpp>
#endif
#if defined(TEST_CPP_BIN_FLOAT)
#include <boost/multiprecision/cpp_dec_float.hpp>
#endif
#if defined(TEST_FLOAT128)
#include <boost/multiprecision/float128.hpp>
#endif
#include "performance_test_df.hpp"
// cd /mnt/c/Users/ckorm/Documents/Ks/PC_Software/Test
// g++ -std=gnu++14 -Wall -Wextra -O3 -I/mnt/c/ChrisGitRepos/modular_boost/multiprecision/performance -I/mnt/c/ChrisGitRepos/modular_boost/multiprecision/include -I/mnt/c/boost/boost_1_89_0 ./test.cpp -lquadmath -o test
//
// Keys in order are:
// Category
// Operator
// Type
// Precision
// Time
//
std::map<std::string, std::map<std::string, std::map<std::string, std::map<int, double> > > > result_table;
unsigned bits_wanted; // for integer types
void quickbook_results()
{
//
// Keys in order are:
// Category
// Operator
// Type
// Precision
// Time
//
typedef std::map<std::string, std::map<std::string, std::map<std::string, std::map<int, double> > > >::const_iterator category_iterator;
typedef std::map<std::string, std::map<std::string, std::map<int, double> > >::const_iterator operator_iterator;
typedef std::map<std::string, std::map<int, double> >::const_iterator type_iterator;
typedef std::map<int, double>::const_iterator precision_iterator;
for (category_iterator i = result_table.begin(); i != result_table.end(); ++i)
{
std::string cat = i->first;
cat[0] = (char)std::toupper((char)cat[0]);
std::cout << "[section:" << i->first << "_performance " << cat << " Type Perfomance]" << std::endl;
for (operator_iterator j = i->second.begin(); j != i->second.end(); ++j)
{
std::string op = j->first;
std::cout << "[table Operator " << op << std::endl;
std::cout << "[[Backend]";
for (precision_iterator k = j->second.begin()->second.begin(); k != j->second.begin()->second.end(); ++k)
{
std::cout << "[" << k->first << " Bits]";
}
std::cout << "]\n";
std::vector<double> best_times(j->second.begin()->second.size(), (std::numeric_limits<double>::max)());
for (unsigned m = 0; m < j->second.begin()->second.size(); ++m)
{
for (type_iterator k = j->second.begin(); k != j->second.end(); ++k)
{
if (m < k->second.size())
{
precision_iterator l = k->second.begin();
std::advance(l, m);
if (best_times[m] > l->second)
best_times[m] = l->second ? l->second : best_times[m];
}
}
}
for (type_iterator k = j->second.begin(); k != j->second.end(); ++k)
{
std::cout << "[[" << k->first << "]";
unsigned m = 0;
for (precision_iterator l = k->second.begin(); l != k->second.end(); ++l)
{
double rel_time = l->second / best_times[m];
if (rel_time == 1)
std::cout << "[[*" << rel_time << "]";
else
std::cout << "[" << rel_time;
std::cout << " (" << l->second << "s)]";
++m;
}
std::cout << "]\n";
}
std::cout << "]\n";
}
std::cout << "[endsect]" << std::endl;
}
}
#if defined(__HAS_INCLUDE)
#if __has_include(<sys/utsname.h>)
#define HAS_UTSNAME
#include <sys/utsname.h>
#endif
#endif
#ifdef _WIN32
#include <windows.h>
#endif
void quickbook_platform_details()
{
std::cout << "[table:platform Platform Details\n[[Platform][";
#ifdef HAS_UTSNAME
utsname name;
uname(&name);
std::cout << name.sysname << " " << name.release << ", version " << name.version << ", " << name.machine << "]]\n";
#elif defined(_WIN32)
std::cout << "Windows ";
#ifdef _M_AMD64
std::cout << "x64";
#elif defined(_M_IX86)
std::cout << "x86";
#endif
std::cout << "]]\n";
#endif
std::cout << "[[Compiler][" << BOOST_COMPILER << "]]\n";
std::cout << "[[Boost][" << BOOST_VERSION << "]]\n";
std::cout << "[[Run date][" << __DATE__ << "]]\n";
std::cout << "]\n\n";
}
namespace local {
void test29();
void test32();
void test52();
void test53();
#ifdef TEST_CPP_DOUBLE_FLOAT
template<class T>
constexpr inline auto (max)(T a, T b) noexcept -> T { return a > b ? a : b; }
#endif
} // namespace local
int main()
{
quickbook_platform_details();
local::test29();
local::test32();
local::test52();
#if defined(BOOST_MP_CPP_DOUBLE_FP_HAS_FLOAT128)
local::test53();
#endif
quickbook_results();
}
#ifdef TEST_CPP_DOUBLE_FLOAT
using double_float_of_double_type = boost::multiprecision::cpp_double_double;
constexpr auto digits10_for_performance_test = (local::max)(std::numeric_limits<double_float_of_double_type>::digits10, 32);
#else
constexpr auto digits10_for_performance_test = 32;
#endif
void local::test29()
{
#ifdef TEST_CPP_DEC_FLOAT
static_assert(digits10_for_performance_test >= 32, "Error: Too few digits for performance comparison");
using cpp_dec_float_type =
boost::multiprecision::number<boost::multiprecision::backends::cpp_dec_float<digits10_for_performance_test>,
boost::multiprecision::et_off>;
test<cpp_dec_float_type>("cpp_dec_float", digits10_for_performance_test);
#endif
}
void local::test32()
{
#ifdef TEST_CPP_BIN_FLOAT
static_assert(digits10_for_performance_test >= 32, "Error: Too few digits for performance comparison");
using cpp_bin_float_type =
boost::multiprecision::number<boost::multiprecision::backends::cpp_bin_float<digits10_for_performance_test, boost::multiprecision::digit_base_10, void>,
boost::multiprecision::et_off>;
test<cpp_bin_float_type>("cpp_bin_float", digits10_for_performance_test);
#endif
}
void local::test52()
{
#ifdef TEST_CPP_DOUBLE_FLOAT
test<double_float_of_double_type>("cpp_double_fp_backend<double>", digits10_for_performance_test);
#endif
}
void local::test53()
{
#if defined(BOOST_HAS_FLOAT128)
#ifdef TEST_FLOAT128
using boost::multiprecision::float128;
test<float128>("boost::multiprecision::float128(at)", std::numeric_limits<boost::multiprecision::float128>::digits10);
#endif
#endif
}
#if 0
See also: https://github.com/BoostGSoC21/multiprecision/issues/178#issuecomment-2580157139
## section:float_performance Float Type Perfomance
| Operation | `float128` |`cpp_bin_float<32>` | `cpp_dec_float<32>` | `cpp_double_fp_backend<double>` |
|---------------------------------|----------------------|------------------------|------------------------|---------------------------------|
| `*` | 1.45209 (0.0530208s) | 1.4866 (0.054281s) | 4.38403 (0.160076s) | [*1] (0.0365135s) |
| `*(int)` | 1.54876 (0.0396009s) | 2.08722 (0.0533689s) | 5.97016 (0.152653s) | [*1] (0.0255694s) |
| `*(unsigned long long)` | 1.66579 (0.083952s) | 1.109 (0.0558912s) | 3.64263 (0.18358s) | [*1] (0.0503976s) |
| `*=(unsigned long long)` | 1.70531 (0.0858822s) | 1.06861 (0.053817s) | 3.47129 (0.17482s) | [*1] (0.0503617s) |
| `+` | 2.4858 (0.0430852s) | 5.38736 (0.0933768s) | 3.06832 (0.0531818s) | [*1] (0.0173326s) |
| `+(int)` | 2.96871 (0.0360276s) | 7.95354 (0.0965222s) | 5.97545 (0.0725166s) | [*1] (0.0121358s) |
| `+(unsigned long long)` | 3.38383 (0.0739771s) | 5.51557 (0.120581s) | 4.42454 (0.0967292s) | [*1] (0.021862s) |
| `+=(unsigned long long)` | 3.3944 (0.0760423s) | 4.98724 (0.111726s) | 3.92369 (0.0878995s) | [*1] (0.0224023s) |
| `-` | 2.20087 (0.0389465s) | 5.40743 (0.0956897s) | 3.24191 (0.0573686s) | [*1] (0.0176959s) |
| `-(int)` | 3.21093 (0.0383358s) | 8.65589 (0.103344s) | 7.53768 (0.0899936s) | [*1] (0.0119392s) |
| `-(unsigned long long)` | 3.45536 (0.075553s) | 5.17747 (0.113208s) | 4.63221 (0.101285s) | [*1] (0.0218654s) |
| `-=(unsigned long long)` | 2.73635 (0.0764208s) | 3.773 (0.105372s) | 3.39784 (0.0948951s) | [*1] (0.027928s) |
| `/` | 1.38437 (0.148412s) | 7.55692 (0.810141s) | 23.5198 (2.52144s) | [*1] (0.107205s) |
| `/(int)` | 1.53126 (0.0384472s) | 6.85045 (0.172002s) | 49.004 (1.2304s) | [*1] (0.0251081s) |
| `/(unsigned long long)` | 2.41876 (0.098966s) | 9.80113 (0.401023s) | 30.6916 (1.25578s) | [*1] (0.040916s) |
| `/=(unsigned long long)` | 1.88263 (0.0994829s) | 7.33976 (0.387852s) | 23.6024 (1.24721s) | [*1] (0.0528426s) |
| `construct` | [*1] (0.000550501s) | 4.74042 (0.00260961s) | 13.0381 (0.00717748s) | 3.51129 (0.00193297s) |
| `construct(unsigned long long)` | 5.33373 (0.0401408s) | 2.82475 (0.0212586s) | 3.38482 (0.0254736s) | [*1] (0.00752583s) |
| `construct(unsigned)` | 23.3495 (0.0403851s) | 12.4928 (0.0216075s) | 14.3869 (0.0248834s) | [*1] (0.00172959s) |
| `exp` | 1.37724 (1.66978s) | 5.45487 (6.61357s) | 5.19473 (6.29817s) | [*1] (1.21242s) |
| `log` | [*1] (2.1149s) | 7.38874 (15.6264s) | 27.0206 (57.146s) | 1.10118 (2.32888s) |
| `sqrt` | 25.9413 (0.53951s) | 24.5484 (0.510541s) | 131.925 (2.74368s) | [*1] (0.0207973s) |
| `str` | [*1] (0.000419145s) | 1.50425 (0.000630497s) | 1.22795 (0.000514689s) | 1.82207 (0.000763711s) |
| `tan` | 1.3995 (1.69463s) | 5.46528 (6.61782s) | 5.20608 (6.30396s) | [*1] (1.21088s) |
#endif
|