1 ///////////////////////////////////////////////////////////////
2 // Copyright 2011 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
6 #define BOOST_CHRONO_HEADER_ONLY
9 #define _SCL_SECURE_NO_WARNINGS
12 #if !defined(TEST_MPF) && !defined(TEST_MPZ) && \
13 !defined(TEST_CPP_DEC_FLOAT) && !defined(TEST_MPFR) && !defined(TEST_MPQ) && !defined(TEST_TOMMATH) && !defined(TEST_TOMMATH_BOOST_RATIONAL) && !defined(TEST_MPZ_BOOST_RATIONAL) && !defined(TEST_CPP_INT) && !defined(TEST_CPP_INT_RATIONAL) && !defined(TEST_CPP_BIN_FLOAT)
18 #define TEST_CPP_DEC_FLOAT
22 #define TEST_CPP_INT_RATIONAL
23 #define TEST_CPP_BIN_FLOAT
26 #pragma message("CAUTION!!: No backend type specified so testing everything.... this will take some time!!")
29 #pragma warning "CAUTION!!: No backend type specified so testing everything.... this will take some time!!"
34 #if defined(TEST_MPF) || defined(TEST_MPZ) || defined(TEST_MPQ) || defined(TEST_MPZ_BOOST_RATIONAL)
35 #include <boost/multiprecision/gmp.hpp>
36 #include <boost/multiprecision/rational_adaptor.hpp>
38 #ifdef TEST_CPP_DEC_FLOAT
39 #include <boost/multiprecision/cpp_dec_float.hpp>
41 #ifdef TEST_CPP_BIN_FLOAT
42 #include <boost/multiprecision/cpp_bin_float.hpp>
44 #if defined(TEST_MPFR)
45 #include <boost/multiprecision/mpfr.hpp>
47 #if defined(TEST_TOMMATH) || defined(TEST_TOMMATH_BOOST_RATIONAL)
48 #include <boost/multiprecision/tommath.hpp>
49 #include <boost/multiprecision/rational_adaptor.hpp>
51 #if defined(TEST_CPP_INT) || defined(TEST_CPP_INT_RATIONAL)
52 #include <boost/multiprecision/cpp_int.hpp>
55 #include <boost/chrono.hpp>
63 #include <boost/random/mersenne_twister.hpp>
64 #include <boost/random/uniform_int.hpp>
66 template <class Clock
>
69 typedef typename
Clock::duration duration
;
72 m_start
= Clock::now();
76 return Clock::now() - m_start
;
80 m_start
= Clock::now();
84 typename
Clock::time_point m_start
;
87 unsigned bits_wanted
; // for integer types
89 template <class T
, int Type
>
95 for (int i
= 0; i
< 500; ++i
)
97 b
.push_back(generate_random());
98 c
.push_back(generate_random());
99 small
.push_back(gen());
104 stopwatch
<boost::chrono::high_resolution_clock
> w
;
105 for (unsigned i
= 0; i
< 1000; ++i
)
107 for (unsigned i
= 0; i
< b
.size(); ++i
)
110 return boost::chrono::duration_cast
<boost::chrono::duration
<double> >(w
.elapsed()).count();
112 double test_subtract()
114 stopwatch
<boost::chrono::high_resolution_clock
> w
;
115 for (unsigned i
= 0; i
< 1000; ++i
)
117 for (unsigned i
= 0; i
< b
.size(); ++i
)
120 return boost::chrono::duration_cast
<boost::chrono::duration
<double> >(w
.elapsed()).count();
122 double test_add_int()
124 stopwatch
<boost::chrono::high_resolution_clock
> w
;
125 for (unsigned i
= 0; i
< 1000; ++i
)
127 for (unsigned i
= 0; i
< b
.size(); ++i
)
130 return boost::chrono::duration_cast
<boost::chrono::duration
<double> >(w
.elapsed()).count();
132 double test_subtract_int()
134 stopwatch
<boost::chrono::high_resolution_clock
> w
;
135 for (unsigned i
= 0; i
< 1000; ++i
)
137 for (unsigned i
= 0; i
< b
.size(); ++i
)
140 return boost::chrono::duration_cast
<boost::chrono::duration
<double> >(w
.elapsed()).count();
142 double test_multiply()
144 stopwatch
<boost::chrono::high_resolution_clock
> w
;
145 for (unsigned i
= 0; i
< 1000; ++i
)
147 for (unsigned k
= 0; k
< b
.size(); ++k
)
150 return boost::chrono::duration_cast
<boost::chrono::duration
<double> >(w
.elapsed()).count();
152 double test_multiply_int()
154 stopwatch
<boost::chrono::high_resolution_clock
> w
;
155 for (unsigned i
= 0; i
< 1000; ++i
)
157 for (unsigned i
= 0; i
< b
.size(); ++i
)
160 return boost::chrono::duration_cast
<boost::chrono::duration
<double> >(w
.elapsed()).count();
164 stopwatch
<boost::chrono::high_resolution_clock
> w
;
165 for (unsigned i
= 0; i
< 1000; ++i
)
167 for (unsigned i
= 0; i
< b
.size(); ++i
)
168 a
[i
] = b
[i
] / c
[i
] + b
[i
] / small
[i
];
170 return boost::chrono::duration_cast
<boost::chrono::duration
<double> >(w
.elapsed()).count();
172 double test_divide_int()
174 stopwatch
<boost::chrono::high_resolution_clock
> w
;
175 for (unsigned i
= 0; i
< 1000; ++i
)
177 for (unsigned i
= 0; i
< b
.size(); ++i
)
180 return boost::chrono::duration_cast
<boost::chrono::duration
<double> >(w
.elapsed()).count();
182 double test_str(const boost::mpl::false_
&)
184 stopwatch
<boost::chrono::high_resolution_clock
> w
;
185 for (unsigned i
= 0; i
< b
.size(); ++i
)
186 a
[i
] = boost::lexical_cast
<T
>(boost::lexical_cast
<std::string
>(b
[i
]));
187 return boost::chrono::duration_cast
<boost::chrono::duration
<double> >(w
.elapsed()).count();
189 double test_str(const boost::mpl::true_
&)
191 stopwatch
<boost::chrono::high_resolution_clock
> w
;
192 for (unsigned i
= 0; i
< b
.size(); ++i
)
193 a
[i
].assign(b
[i
].str());
194 return boost::chrono::duration_cast
<boost::chrono::duration
<double> >(w
.elapsed()).count();
198 return test_str(boost::is_class
<T
>());
201 // The following tests only work for integer types:
205 stopwatch
<boost::chrono::high_resolution_clock
> w
;
206 for (unsigned i
= 0; i
< 1000; ++i
)
208 for (unsigned i
= 0; i
< b
.size(); ++i
)
209 a
[i
] = b
[i
] % c
[i
] + b
[i
] % small
[i
];
211 return boost::chrono::duration_cast
<boost::chrono::duration
<double> >(w
.elapsed()).count();
213 double test_mod_int()
215 stopwatch
<boost::chrono::high_resolution_clock
> w
;
216 for (unsigned i
= 0; i
< 1000; ++i
)
218 for (unsigned i
= 0; i
< b
.size(); ++i
)
221 return boost::chrono::duration_cast
<boost::chrono::duration
<double> >(w
.elapsed()).count();
225 stopwatch
<boost::chrono::high_resolution_clock
> w
;
226 for (unsigned i
= 0; i
< 1000; ++i
)
228 for (unsigned i
= 0; i
< b
.size(); ++i
)
231 return boost::chrono::duration_cast
<boost::chrono::duration
<double> >(w
.elapsed()).count();
235 stopwatch
<boost::chrono::high_resolution_clock
> w
;
236 for (unsigned i
= 0; i
< 1000; ++i
)
238 for (unsigned i
= 0; i
< b
.size(); ++i
)
241 return boost::chrono::duration_cast
<boost::chrono::duration
<double> >(w
.elapsed()).count();
245 stopwatch
<boost::chrono::high_resolution_clock
> w
;
246 for (unsigned i
= 0; i
< 1000; ++i
)
248 for (unsigned i
= 0; i
< b
.size(); ++i
)
251 return boost::chrono::duration_cast
<boost::chrono::duration
<double> >(w
.elapsed()).count();
253 double test_and_int()
255 stopwatch
<boost::chrono::high_resolution_clock
> w
;
256 for (unsigned i
= 0; i
< 1000; ++i
)
258 for (unsigned i
= 0; i
< b
.size(); ++i
)
261 return boost::chrono::duration_cast
<boost::chrono::duration
<double> >(w
.elapsed()).count();
265 stopwatch
<boost::chrono::high_resolution_clock
> w
;
266 for (unsigned i
= 0; i
< 1000; ++i
)
268 for (unsigned i
= 0; i
< b
.size(); ++i
)
271 return boost::chrono::duration_cast
<boost::chrono::duration
<double> >(w
.elapsed()).count();
273 double test_xor_int()
275 stopwatch
<boost::chrono::high_resolution_clock
> w
;
276 for (unsigned i
= 0; i
< 1000; ++i
)
278 for (unsigned i
= 0; i
< b
.size(); ++i
)
281 return boost::chrono::duration_cast
<boost::chrono::duration
<double> >(w
.elapsed()).count();
283 double test_complement()
285 stopwatch
<boost::chrono::high_resolution_clock
> w
;
286 for (unsigned i
= 0; i
< 1000; ++i
)
288 for (unsigned i
= 0; i
< b
.size(); ++i
)
291 return boost::chrono::duration_cast
<boost::chrono::duration
<double> >(w
.elapsed()).count();
293 double test_left_shift()
295 int max_shift
= std::numeric_limits
<T
>::is_bounded
? std::numeric_limits
<T
>::digits
: bits_wanted
;
297 stopwatch
<boost::chrono::high_resolution_clock
> w
;
298 for (unsigned i
= 0; i
< 1000; ++i
)
300 for (unsigned i
= 0; i
< b
.size(); ++i
)
301 a
[i
] = b
[i
] << (shift
++ % max_shift
);
303 return boost::chrono::duration_cast
<boost::chrono::duration
<double> >(w
.elapsed()).count();
305 double test_right_shift()
307 int max_shift
= 2 + std::numeric_limits
<T
>::is_bounded
? std::numeric_limits
<T
>::digits
: bits_wanted
;
309 stopwatch
<boost::chrono::high_resolution_clock
> w
;
310 for (unsigned i
= 0; i
< 1000; ++i
)
312 for (unsigned i
= 0; i
< b
.size(); ++i
)
313 a
[i
] = b
[i
] >> (shift
++) % max_shift
;
315 return boost::chrono::duration_cast
<boost::chrono::duration
<double> >(w
.elapsed()).count();
319 using boost::integer::gcd
;
320 stopwatch
<boost::chrono::high_resolution_clock
> w
;
321 for (unsigned i
= 0; i
< 1000; ++i
)
323 for (unsigned i
= 0; i
< b
.size(); ++i
)
324 a
[i
] = gcd(b
[i
], c
[i
]);
326 return boost::chrono::duration_cast
<boost::chrono::duration
<double> >(w
.elapsed()).count();
330 stopwatch
<boost::chrono::high_resolution_clock
> w
;
331 for (unsigned i
= 0; i
< 25; ++i
)
333 for (unsigned i
= 0; i
< b
.size(); ++i
)
334 a
[i
] = powm(b
[i
], b
[i
] / 2, c
[i
]);
336 return boost::chrono::duration_cast
<boost::chrono::duration
<double> >(w
.elapsed()).count();
338 double test_construct()
341 T
* pt
= a
.allocate(1000);
342 stopwatch
<boost::chrono::high_resolution_clock
> w
;
343 for (unsigned i
= 0; i
< 1000; ++i
)
345 for (unsigned i
= 0; i
< 1000; ++i
)
347 for (unsigned i
= 0; i
< 1000; ++i
)
350 double result
= boost::chrono::duration_cast
<boost::chrono::duration
<double> >(w
.elapsed()).count();
351 a
.deallocate(pt
, 1000);
354 double test_construct_unsigned()
357 T
* pt
= a
.allocate(1000);
358 stopwatch
<boost::chrono::high_resolution_clock
> w
;
359 for (unsigned i
= 0; i
< 1000; ++i
)
361 for (unsigned i
= 0; i
< 1000; ++i
)
363 for (unsigned i
= 0; i
< 1000; ++i
)
366 double result
= boost::chrono::duration_cast
<boost::chrono::duration
<double> >(w
.elapsed()).count();
367 a
.deallocate(pt
, 1000);
370 double test_construct_unsigned_ll()
373 T
* pt
= a
.allocate(1000);
374 stopwatch
<boost::chrono::high_resolution_clock
> w
;
375 for (unsigned i
= 0; i
< 1000; ++i
)
377 for (unsigned long long j
= 0; j
< 1000; ++j
)
379 for (unsigned j
= 0; j
< 1000; ++j
)
382 double result
= boost::chrono::duration_cast
<boost::chrono::duration
<double> >(w
.elapsed()).count();
383 a
.deallocate(pt
, 1000);
388 // Hetero operations:
391 static U
get_hetero_test_value(boost::mpl::false_
const&)
396 static U
get_hetero_test_value(boost::mpl::true_
const&)
398 return (std::numeric_limits
<U
>::max
)() >> 4;
401 static U
get_hetero_test_value()
403 return get_hetero_test_value
<U
>(boost::is_integral
<U
>());
406 double test_multiply_hetero()
408 static const U val
= get_hetero_test_value
<U
>();
409 stopwatch
<boost::chrono::high_resolution_clock
> w
;
410 for (unsigned i
= 0; i
< 1000; ++i
)
412 for (unsigned i
= 0; i
< b
.size(); ++i
)
415 return boost::chrono::duration_cast
<boost::chrono::duration
<double> >(w
.elapsed()).count();
418 double test_inplace_multiply_hetero()
420 static const U val
= get_hetero_test_value
<U
>();
421 for (unsigned i
= 0; i
< b
.size(); ++i
)
423 stopwatch
<boost::chrono::high_resolution_clock
> w
;
424 for (unsigned i
= 0; i
< 1000; ++i
)
426 for (unsigned i
= 0; i
< b
.size(); ++i
)
429 return boost::chrono::duration_cast
<boost::chrono::duration
<double> >(w
.elapsed()).count();
432 double test_add_hetero()
434 static const U val
= get_hetero_test_value
<U
>();
435 stopwatch
<boost::chrono::high_resolution_clock
> w
;
436 for (unsigned i
= 0; i
< 1000; ++i
)
438 for (unsigned i
= 0; i
< b
.size(); ++i
)
441 return boost::chrono::duration_cast
<boost::chrono::duration
<double> >(w
.elapsed()).count();
444 double test_inplace_add_hetero()
446 static const U val
= get_hetero_test_value
<U
>();
447 for (unsigned i
= 0; i
< b
.size(); ++i
)
449 stopwatch
<boost::chrono::high_resolution_clock
> w
;
450 for (unsigned i
= 0; i
< 1000; ++i
)
452 for (unsigned i
= 0; i
< b
.size(); ++i
)
455 return boost::chrono::duration_cast
<boost::chrono::duration
<double> >(w
.elapsed()).count();
458 double test_subtract_hetero()
460 static const U val
= get_hetero_test_value
<U
>();
461 stopwatch
<boost::chrono::high_resolution_clock
> w
;
462 for (unsigned i
= 0; i
< 1000; ++i
)
464 for (unsigned i
= 0; i
< b
.size(); ++i
)
467 return boost::chrono::duration_cast
<boost::chrono::duration
<double> >(w
.elapsed()).count();
470 double test_inplace_subtract_hetero()
472 static const U val
= get_hetero_test_value
<U
>();
473 for (unsigned i
= 0; i
< b
.size(); ++i
)
475 stopwatch
<boost::chrono::high_resolution_clock
> w
;
476 for (unsigned i
= 0; i
< 1000; ++i
)
478 for (unsigned i
= 0; i
< b
.size(); ++i
)
481 return boost::chrono::duration_cast
<boost::chrono::duration
<double> >(w
.elapsed()).count();
484 double test_divide_hetero()
486 static const U val
= get_hetero_test_value
<U
>();
487 stopwatch
<boost::chrono::high_resolution_clock
> w
;
488 for (unsigned i
= 0; i
< 1000; ++i
)
490 for (unsigned i
= 0; i
< b
.size(); ++i
)
493 return boost::chrono::duration_cast
<boost::chrono::duration
<double> >(w
.elapsed()).count();
496 double test_inplace_divide_hetero()
498 static const U val
= get_hetero_test_value
<U
>();
499 for (unsigned i
= 0; i
< b
.size(); ++i
)
501 stopwatch
<boost::chrono::high_resolution_clock
> w
;
502 for (unsigned i
= 0; i
< 1000; ++i
)
504 for (unsigned i
= 0; i
< b
.size(); ++i
)
507 return boost::chrono::duration_cast
<boost::chrono::duration
<double> >(w
.elapsed()).count();
513 return generate_random(boost::mpl::int_
<Type
>());
515 T
generate_random(const boost::mpl::int_
<boost::multiprecision::number_kind_floating_point
>&)
519 while (val
!= prev_val
)
526 val
= frexp(val
, &e
);
528 typedef typename
T::backend_type::exponent_type e_type
;
529 static boost::random::uniform_int_distribution
<e_type
> ui(-30, 30);
530 return ldexp(val
, static_cast<int>(ui(gen
)));
532 T
generate_random(const boost::mpl::int_
<boost::multiprecision::number_kind_integer
>&)
534 typedef boost::random::mt19937::result_type random_type
;
538 if (std::numeric_limits
<T
>::is_bounded
)
540 max_val
= (std::numeric_limits
<T
>::max
)();
541 digits
= std::numeric_limits
<T
>::digits
;
545 max_val
= T(1) << bits_wanted
;
546 digits
= bits_wanted
;
549 unsigned bits_per_r_val
= std::numeric_limits
<random_type
>::digits
- 1;
550 while ((random_type(1) << bits_per_r_val
) > (gen
.max
)())
553 unsigned terms_needed
= digits
/ bits_per_r_val
+ 1;
556 for (unsigned i
= 0; i
< terms_needed
; ++i
)
564 T
generate_random(const boost::mpl::int_
<boost::multiprecision::number_kind_rational
>&)
566 typedef boost::random::mt19937::result_type random_type
;
567 typedef typename
boost::multiprecision::component_type
<T
>::type IntType
;
571 if (std::numeric_limits
<IntType
>::is_bounded
)
573 max_val
= (std::numeric_limits
<IntType
>::max
)();
574 digits
= std::numeric_limits
<IntType
>::digits
;
578 max_val
= IntType(1) << bits_wanted
;
579 digits
= bits_wanted
;
582 unsigned bits_per_r_val
= std::numeric_limits
<random_type
>::digits
- 1;
583 while ((random_type(1) << bits_per_r_val
) > (gen
.max
)())
586 unsigned terms_needed
= digits
/ bits_per_r_val
+ 1;
590 for (unsigned i
= 0; i
< terms_needed
; ++i
)
595 for (unsigned i
= 0; i
< terms_needed
; ++i
)
597 denom
*= (gen
.max
)();
604 return T(val
, denom
);
606 std::vector
<T
> a
, b
, c
, small
;
607 static boost::random::mt19937 gen
;
610 template <class N
, int V
>
611 boost::random::mt19937 tester
<N
, V
>::gen
;
613 const char* category_name(const boost::mpl::int_
<boost::multiprecision::number_kind_integer
>&)
617 const char* category_name(const boost::mpl::int_
<boost::multiprecision::number_kind_floating_point
>&)
621 const char* category_name(const boost::mpl::int_
<boost::multiprecision::number_kind_rational
>&)
627 // Keys in order are:
634 std::map
<std::string
, std::map
<std::string
, std::map
<std::string
, std::map
<int, double> > > > result_table
;
636 void report_result(const char* cat
, const char* type
, const char* op
, unsigned precision
, double time
)
638 std::cout
<< std::left
<< std::setw(15) << type
<< std::setw(10) << precision
<< std::setw(35) << op
<< time
<< std::endl
;
639 result_table
[cat
][op
][type
][precision
] = time
;
642 template <class Number
, int N
>
643 void test_int_ops(tester
<Number
, N
>& t
, const char* type
, unsigned precision
, const boost::mpl::int_
<boost::multiprecision::number_kind_integer
>&)
645 const char* cat
= "integer";
646 report_result(cat
, type
, "%", precision
, t
.test_mod());
647 report_result(cat
, type
, "|", precision
, t
.test_or());
648 report_result(cat
, type
, "&", precision
, t
.test_and());
649 report_result(cat
, type
, "^", precision
, t
.test_xor());
650 //report_result(cat, type, "~", precision, t.test_complement());
651 report_result(cat
, type
, "<<", precision
, t
.test_left_shift());
652 report_result(cat
, type
, ">>", precision
, t
.test_right_shift());
654 report_result(cat
, type
, "%(int)", precision
, t
.test_mod_int());
655 report_result(cat
, type
, "|(int)", precision
, t
.test_or_int());
656 report_result(cat
, type
, "&(int)", precision
, t
.test_and_int());
657 report_result(cat
, type
, "^(int)", precision
, t
.test_xor_int());
658 report_result(cat
, type
, "gcd", precision
, t
.test_gcd());
659 report_result(cat
, type
, "powm", precision
, t
.test_powm());
661 template <class Number
, int N
, class U
>
662 void test_int_ops(tester
<Number
, N
>& t
, const char* type
, unsigned precision
, const U
&)
666 template <class Number
>
667 void test(const char* type
, unsigned precision
)
669 bits_wanted
= precision
;
670 tester
<Number
, boost::multiprecision::number_category
<Number
>::value
> t
;
671 const char* cat
= category_name(typename
boost::multiprecision::number_category
<Number
>::type());
673 // call t.test_multiply() first so that the destination operands are
674 // forced to perform whatever memory allocation may be needed. That way
675 // we measure only algorithm performance, and not memory allocation effects.
679 // Now the actual tests:
681 report_result(cat
, type
, "+", precision
, t
.test_add());
682 report_result(cat
, type
, "-", precision
, t
.test_subtract());
683 report_result(cat
, type
, "*", precision
, t
.test_multiply());
684 report_result(cat
, type
, "/", precision
, t
.test_divide());
685 report_result(cat
, type
, "str", precision
, t
.test_str());
687 report_result(cat
, type
, "+(int)", precision
, t
.test_add_int());
688 report_result(cat
, type
, "-(int)", precision
, t
.test_subtract_int());
689 report_result(cat
, type
, "*(int)", precision
, t
.test_multiply_int());
690 report_result(cat
, type
, "/(int)", precision
, t
.test_divide_int());
691 // construction and destruction:
692 report_result(cat
, type
, "construct", precision
, t
.test_construct());
693 report_result(cat
, type
, "construct(unsigned)", precision
, t
.test_construct_unsigned());
694 report_result(cat
, type
, "construct(unsigned long long)", precision
, t
.test_construct_unsigned_ll());
695 test_int_ops(t
, type
, precision
, typename
boost::multiprecision::number_category
<Number
>::type());
697 report_result(cat
, type
, "+(unsigned long long)", precision
, t
.template test_add_hetero
<unsigned long long>());
698 report_result(cat
, type
, "-(unsigned long long)", precision
, t
.template test_subtract_hetero
<unsigned long long>());
699 report_result(cat
, type
, "*(unsigned long long)", precision
, t
.template test_multiply_hetero
<unsigned long long>());
700 report_result(cat
, type
, "/(unsigned long long)", precision
, t
.template test_divide_hetero
<unsigned long long>());
701 report_result(cat
, type
, "+=(unsigned long long)", precision
, t
.template test_inplace_add_hetero
<unsigned long long>());
702 report_result(cat
, type
, "-=(unsigned long long)", precision
, t
.template test_inplace_subtract_hetero
<unsigned long long>());
703 report_result(cat
, type
, "*=(unsigned long long)", precision
, t
.template test_inplace_multiply_hetero
<unsigned long long>());
704 report_result(cat
, type
, "/=(unsigned long long)", precision
, t
.template test_inplace_divide_hetero
<unsigned long long>());
707 void quickbook_results()
710 // Keys in order are:
717 typedef std::map
<std::string
, std::map
<std::string
, std::map
<std::string
, std::map
<int, double> > > >::const_iterator category_iterator
;
718 typedef std::map
<std::string
, std::map
<std::string
, std::map
<int, double> > >::const_iterator operator_iterator
;
719 typedef std::map
<std::string
, std::map
<int, double> >::const_iterator type_iterator
;
720 typedef std::map
<int, double>::const_iterator precision_iterator
;
722 for (category_iterator i
= result_table
.begin(); i
!= result_table
.end(); ++i
)
724 std::string cat
= i
->first
;
725 cat
[0] = std::toupper(cat
[0]);
726 std::cout
<< "[section:" << i
->first
<< "_performance " << cat
<< " Type Perfomance]" << std::endl
;
728 for (operator_iterator j
= i
->second
.begin(); j
!= i
->second
.end(); ++j
)
730 std::string op
= j
->first
;
731 std::cout
<< "[table Operator " << op
<< std::endl
;
732 std::cout
<< "[[Backend]";
734 for (precision_iterator k
= j
->second
.begin()->second
.begin(); k
!= j
->second
.begin()->second
.end(); ++k
)
736 std::cout
<< "[" << k
->first
<< " Bits]";
740 std::vector
<double> best_times(j
->second
.begin()->second
.size(), (std::numeric_limits
<double>::max
)());
741 for (unsigned m
= 0; m
< j
->second
.begin()->second
.size(); ++m
)
743 for (type_iterator k
= j
->second
.begin(); k
!= j
->second
.end(); ++k
)
745 precision_iterator l
= k
->second
.begin();
747 if (best_times
[m
] > l
->second
)
748 best_times
[m
] = l
->second
? l
->second
: best_times
[m
];
752 for (type_iterator k
= j
->second
.begin(); k
!= j
->second
.end(); ++k
)
754 std::cout
<< "[[" << k
->first
<< "]";
757 for (precision_iterator l
= k
->second
.begin(); l
!= k
->second
.end(); ++l
)
759 double rel_time
= l
->second
/ best_times
[m
];
761 std::cout
<< "[[*" << rel_time
<< "]";
763 std::cout
<< "[" << rel_time
;
764 std::cout
<< " (" << l
->second
<< "s)]";
774 std::cout
<< "[endsect]" << std::endl
;
781 test
<boost::uint64_t>("boost::uint64_t", 64);
784 test
<boost::multiprecision::mpf_float_50
>("gmp_float", 50);
785 test
<boost::multiprecision::mpf_float_100
>("gmp_float", 100);
786 test
<boost::multiprecision::mpf_float_500
>("gmp_float", 500);
789 test
<boost::multiprecision::mpz_int
>("gmp_int", 128);
790 test
<boost::multiprecision::mpz_int
>("gmp_int", 256);
791 test
<boost::multiprecision::mpz_int
>("gmp_int", 512);
792 test
<boost::multiprecision::mpz_int
>("gmp_int", 1024);
795 //test<boost::multiprecision::number<boost::multiprecision::cpp_int_backend<64, 64, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void>, boost::multiprecision::et_off> >("cpp_int(unsigned, fixed)", 64);
796 //test<boost::multiprecision::number<boost::multiprecision::cpp_int_backend<64, 64, boost::multiprecision::signed_magnitude, boost::multiprecision::unchecked, void>, boost::multiprecision::et_off> >("cpp_int(fixed)", 64);
797 test
<boost::multiprecision::number
<boost::multiprecision::cpp_int_backend
<128, 128, boost::multiprecision::signed_magnitude
, boost::multiprecision::unchecked
, void>, boost::multiprecision::et_off
> >("cpp_int(fixed)", 128);
798 test
<boost::multiprecision::number
<boost::multiprecision::cpp_int_backend
<256, 256, boost::multiprecision::signed_magnitude
, boost::multiprecision::unchecked
, void>, boost::multiprecision::et_off
> >("cpp_int(fixed)", 256);
799 test
<boost::multiprecision::number
<boost::multiprecision::cpp_int_backend
<512, 512, boost::multiprecision::signed_magnitude
, boost::multiprecision::unchecked
, void>, boost::multiprecision::et_off
> >("cpp_int(fixed)", 512);
800 test
<boost::multiprecision::number
<boost::multiprecision::cpp_int_backend
<1024, 1024, boost::multiprecision::signed_magnitude
, boost::multiprecision::unchecked
, void>, boost::multiprecision::et_off
> >("cpp_int(fixed)", 1024);
802 test
<boost::multiprecision::cpp_int
>("cpp_int", 128);
803 test
<boost::multiprecision::cpp_int
>("cpp_int", 256);
804 test
<boost::multiprecision::cpp_int
>("cpp_int", 512);
805 test
<boost::multiprecision::cpp_int
>("cpp_int", 1024);
807 #ifdef TEST_CPP_INT_RATIONAL
808 test
<boost::multiprecision::cpp_rational
>("cpp_rational", 128);
809 test
<boost::multiprecision::cpp_rational
>("cpp_rational", 256);
810 test
<boost::multiprecision::cpp_rational
>("cpp_rational", 512);
811 test
<boost::multiprecision::cpp_rational
>("cpp_rational", 1024);
814 test
<boost::multiprecision::mpq_rational
>("mpq_rational", 128);
815 test
<boost::multiprecision::mpq_rational
>("mpq_rational", 256);
816 test
<boost::multiprecision::mpq_rational
>("mpq_rational", 512);
817 test
<boost::multiprecision::mpq_rational
>("mpq_rational", 1024);
820 test
<boost::multiprecision::tom_int
>("tommath_int", 128);
821 test
<boost::multiprecision::tom_int
>("tommath_int", 256);
822 test
<boost::multiprecision::tom_int
>("tommath_int", 512);
823 test
<boost::multiprecision::tom_int
>("tommath_int", 1024);
826 // These are actually too slow to test!!!
828 test<boost::multiprecision::tom_rational>("tom_rational", 128);
829 test<boost::multiprecision::tom_rational>("tom_rational", 256);
830 test<boost::multiprecision::tom_rational>("tom_rational", 512);
831 test<boost::multiprecision::tom_rational>("tom_rational", 1024);
834 #ifdef TEST_CPP_DEC_FLOAT
835 test
<boost::multiprecision::cpp_dec_float_50
>("cpp_dec_float", 50);
836 test
<boost::multiprecision::cpp_dec_float_100
>("cpp_dec_float", 100);
837 test
<boost::multiprecision::number
<boost::multiprecision::cpp_dec_float
<500> > >("cpp_dec_float", 500);
839 #ifdef TEST_CPP_BIN_FLOAT
840 test
<boost::multiprecision::cpp_bin_float_50
>("cpp_bin_float", 50);
841 test
<boost::multiprecision::cpp_bin_float_100
>("cpp_bin_float", 100);
842 test
<boost::multiprecision::number
<boost::multiprecision::cpp_bin_float
<500> > >("cpp_bin_float", 500);
845 test
<boost::multiprecision::mpfr_float_50
>("mpfr_float", 50);
846 test
<boost::multiprecision::mpfr_float_100
>("mpfr_float", 100);
847 test
<boost::multiprecision::mpfr_float_500
>("mpfr_float", 500);