]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/multiprecision/performance/sf_performance.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / multiprecision / performance / sf_performance.hpp
CommitLineData
7c673cae
FG
1///////////////////////////////////////////////////////////////
2// Copyright 2011 John Maddock. Distributed under the Boost
3// Software License, Version 1.0. (See accompanying file
92f5a8d4 4// LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt
7c673cae
FG
5
6#define BOOST_MATH_MAX_ROOT_ITERATION_POLICY 750
7#define BOOST_MATH_PROMOTE_DOUBLE_POLICY false
8
92f5a8d4
TL
9#if !defined(TEST_MPFR) && !defined(TEST_MPREAL) && !defined(TEST_MPF) && !defined(TEST_MPREAL) && !defined(TEST_CPP_DEC_FLOAT) && !defined(TEST_MPFR_CLASS) && !defined(TEST_FLOAT) && !defined(TEST_CPP_BIN_FLOAT)
10#define TEST_MPFR
11#define TEST_MPF
12#define TEST_CPP_DEC_FLOAT
13#define TEST_CPP_BIN_FLOAT
7c673cae
FG
14//# define TEST_MPFR_CLASS
15//# define TEST_MPREAL
92f5a8d4 16#define TEST_FLOAT
7c673cae
FG
17#endif
18
19#ifdef TEST_FLOAT
20#include "arithmetic_backend.hpp"
21#endif
22#ifdef TEST_MPFR_CLASS
23#include <boost/math/bindings/mpfr.hpp>
24#endif
25#ifdef TEST_MPFR
26#include <boost/multiprecision/mpfr.hpp>
27#endif
28#ifdef TEST_MPREAL
29#include <boost/math/bindings/mpreal.hpp>
30#endif
31#ifdef TEST_MPF
32#include <boost/multiprecision/gmp.hpp>
33#endif
34#ifdef TEST_CPP_DEC_FLOAT
35#include <boost/multiprecision/cpp_dec_float.hpp>
36#endif
37#ifdef TEST_CPP_BIN_FLOAT
38#include <boost/multiprecision/cpp_bin_float.hpp>
39#include <boost/multiprecision/mpfr.hpp>
40#endif
41#include <boost/math/special_functions/bessel.hpp>
42#include <boost/math/tools/rational.hpp>
43#include <boost/math/distributions/non_central_t.hpp>
44#include <libs/math/test/table_type.hpp>
45#include <boost/chrono.hpp>
46#include <boost/array.hpp>
47#include <boost/thread.hpp>
48
49template <class Real>
50Real test_bessel();
51
52template <class Clock>
53struct stopwatch
54{
55 typedef typename Clock::duration duration;
56 stopwatch()
57 {
58 m_start = Clock::now();
59 }
60 duration elapsed()
61 {
62 return Clock::now() - m_start;
63 }
64 void reset()
65 {
66 m_start = Clock::now();
67 }
68
92f5a8d4 69 private:
7c673cae
FG
70 typename Clock::time_point m_start;
71};
72
73template <class Real>
74Real test_bessel()
75{
92f5a8d4
TL
76 try
77 {
78#define T double
79#define SC_(x) x
80#include "libs/math/test/bessel_i_int_data.ipp"
81#include "libs/math/test/bessel_i_data.ipp"
7c673cae
FG
82
83 Real r;
84
92f5a8d4 85 for (unsigned i = 0; i < bessel_i_int_data.size(); ++i)
7c673cae
FG
86 {
87 r += boost::math::cyl_bessel_i(Real(bessel_i_int_data[i][0]), Real(bessel_i_int_data[i][1]));
88 }
92f5a8d4 89 for (unsigned i = 0; i < bessel_i_data.size(); ++i)
7c673cae
FG
90 {
91 r += boost::math::cyl_bessel_i(Real(bessel_i_data[i][0]), Real(bessel_i_data[i][1]));
92 }
93
94#include "libs/math/test/bessel_j_int_data.ipp"
92f5a8d4 95 for (unsigned i = 0; i < bessel_j_int_data.size(); ++i)
7c673cae
FG
96 {
97 r += boost::math::cyl_bessel_j(Real(bessel_j_int_data[i][0]), Real(bessel_j_int_data[i][1]));
98 }
99
100#include "libs/math/test/bessel_j_data.ipp"
92f5a8d4 101 for (unsigned i = 0; i < bessel_j_data.size(); ++i)
7c673cae
FG
102 {
103 r += boost::math::cyl_bessel_j(Real(bessel_j_data[i][0]), Real(bessel_j_data[i][1]));
104 }
105
106#include "libs/math/test/bessel_j_large_data.ipp"
92f5a8d4 107 for (unsigned i = 0; i < bessel_j_large_data.size(); ++i)
7c673cae
FG
108 {
109 r += boost::math::cyl_bessel_j(Real(bessel_j_large_data[i][0]), Real(bessel_j_large_data[i][1]));
110 }
111
112#include "libs/math/test/sph_bessel_data.ipp"
92f5a8d4 113 for (unsigned i = 0; i < sph_bessel_data.size(); ++i)
7c673cae
FG
114 {
115 r += boost::math::sph_bessel(static_cast<unsigned>(sph_bessel_data[i][0]), Real(sph_bessel_data[i][1]));
116 }
117
118 return r;
119 }
92f5a8d4 120 catch (const std::exception& e)
7c673cae
FG
121 {
122 std::cout << e.what() << std::endl;
123 }
124 return 0;
125}
126
127template <class Real>
128Real test_polynomial()
129{
130 static const unsigned t[] = {
92f5a8d4 131 2, 3, 4, 5, 6, 7, 8};
7c673cae 132 Real result = 0;
92f5a8d4 133 for (Real k = 2; k < 1000; ++k)
7c673cae
FG
134 result += boost::math::tools::evaluate_polynomial(t, k);
135
136 return result;
137}
138
139template <class Real>
140Real test_nct()
141{
142#define T double
143#include "libs/math/test/nct.ipp"
144
145 Real result = 0;
92f5a8d4 146 for (unsigned i = 0; i < nct.size(); ++i)
7c673cae 147 {
92f5a8d4
TL
148 try
149 {
7c673cae
FG
150 result += quantile(boost::math::non_central_t_distribution<Real>(nct[i][0], nct[i][1]), nct[i][3]);
151 result += cdf(boost::math::non_central_t_distribution<Real>(nct[i][0], nct[i][1]), nct[i][2]);
152 }
92f5a8d4 153 catch (const std::exception&)
7c673cae
FG
154 {}
155 }
156 return result;
157}
158
159extern unsigned allocation_count;
160
161template <class Real>
162void basic_allocation_test(const char* name, Real x)
163{
92f5a8d4
TL
164 static const unsigned a[] = {2, 3, 4, 5, 6, 7, 8};
165 allocation_count = 0;
166 Real result = (((((a[6] * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0];
7c673cae
FG
167 std::cout << "Allocation count for type " << name << " = " << allocation_count << std::endl;
168}
169
170template <class Real>
171void poly_allocation_test(const char* name, Real x)
172{
92f5a8d4
TL
173 static const unsigned a[] = {2, 3, 4, 5, 6, 7, 8};
174 allocation_count = 0;
175 Real result = boost::math::tools::evaluate_polynomial(a, x);
7c673cae
FG
176 std::cout << "Allocation count for type " << name << " = " << allocation_count << std::endl;
177}
178
179template <class Real>
180void time_proc(const char* name, Real (*proc)(), unsigned threads = 1)
181{
92f5a8d4
TL
182 try
183 {
7c673cae 184 static Real total = 0;
92f5a8d4
TL
185 allocation_count = 0;
186 boost::chrono::duration<double> time;
7c673cae
FG
187 stopwatch<boost::chrono::high_resolution_clock> c;
188 total += proc();
189 time = c.elapsed();
190 std::cout << "Time for " << name << " = " << time << std::endl;
191 std::cout << "Total allocations for " << name << " = " << allocation_count << std::endl;
192
92f5a8d4 193 for (unsigned thread_count = 1; thread_count < threads; ++thread_count)
7c673cae
FG
194 {
195 c.reset();
196 boost::thread_group g;
92f5a8d4 197 for (unsigned i = 0; i <= thread_count; ++i)
7c673cae
FG
198 g.create_thread(proc);
199 g.join_all();
200 time = c.elapsed();
201 std::cout << "Time for " << name << " (" << (thread_count + 1) << " threads) = " << time << std::endl;
202 std::cout << "Total allocations for " << name << " = " << allocation_count << std::endl;
203 }
204 }
92f5a8d4 205 catch (const std::exception& e)
7c673cae
FG
206 {
207 std::cout << e.what() << std::endl;
208 }
209}
210
211using namespace boost::multiprecision;
212
213void basic_tests();
214void bessel_tests();
215void poly_tests();
216void nct_tests();