File: sf_performance.hpp

package info (click to toggle)
boost1.62 1.62.0%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 686,420 kB
  • sloc: cpp: 2,609,004; xml: 972,558; ansic: 53,674; python: 32,437; sh: 8,829; asm: 3,071; cs: 2,121; makefile: 964; perl: 859; yacc: 472; php: 132; ruby: 94; f90: 55; sql: 13; csh: 6
file content (214 lines) | stat: -rw-r--r-- 6,100 bytes parent folder | download | duplicates (3)
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
///////////////////////////////////////////////////////////////
//  Copyright 2011 John Maddock. Distributed under the Boost
//  Software License, Version 1.0. (See accompanying file
//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_

#define BOOST_MATH_MAX_ROOT_ITERATION_POLICY 750
#define BOOST_MATH_PROMOTE_DOUBLE_POLICY false

#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)
#  define TEST_MPFR
#  define TEST_MPF
#  define TEST_CPP_DEC_FLOAT
#  define TEST_CPP_BIN_FLOAT
//#  define TEST_MPFR_CLASS
//#  define TEST_MPREAL
#  define TEST_FLOAT
#endif

#ifdef TEST_FLOAT
#include "arithmetic_backend.hpp"
#endif
#ifdef TEST_MPFR_CLASS
#include <boost/math/bindings/mpfr.hpp>
#endif
#ifdef TEST_MPFR
#include <boost/multiprecision/mpfr.hpp>
#endif
#ifdef TEST_MPREAL
#include <boost/math/bindings/mpreal.hpp>
#endif
#ifdef TEST_MPF
#include <boost/multiprecision/gmp.hpp>
#endif
#ifdef TEST_CPP_DEC_FLOAT
#include <boost/multiprecision/cpp_dec_float.hpp>
#endif
#ifdef TEST_CPP_BIN_FLOAT
#include <boost/multiprecision/cpp_bin_float.hpp>
#include <boost/multiprecision/mpfr.hpp>
#endif
#include <boost/math/special_functions/bessel.hpp>
#include <boost/math/tools/rational.hpp>
#include <boost/math/distributions/non_central_t.hpp>
#include <libs/math/test/table_type.hpp>
#include <boost/chrono.hpp>
#include <boost/array.hpp>
#include <boost/thread.hpp>

template <class Real>
Real test_bessel();

template <class Clock>
struct stopwatch
{
   typedef typename Clock::duration duration;
   stopwatch()
   {
      m_start = Clock::now();
   }
   duration elapsed()
   {
      return Clock::now() - m_start;
   }
   void reset()
   {
      m_start = Clock::now();
   }

private:
   typename Clock::time_point m_start;
};

template <class Real>
Real test_bessel()
{
   try{
#  define T double
#  define SC_(x) x
#  include "libs/math/test/bessel_i_int_data.ipp"
#  include "libs/math/test/bessel_i_data.ipp"

      Real r;

      for(unsigned i = 0; i < bessel_i_int_data.size(); ++i)
      {
         r += boost::math::cyl_bessel_i(Real(bessel_i_int_data[i][0]), Real(bessel_i_int_data[i][1]));
      }
      for(unsigned i = 0; i < bessel_i_data.size(); ++i)
      {
         r += boost::math::cyl_bessel_i(Real(bessel_i_data[i][0]), Real(bessel_i_data[i][1]));
      }

#include "libs/math/test/bessel_j_int_data.ipp"
      for(unsigned i = 0; i < bessel_j_int_data.size(); ++i)
      {
         r += boost::math::cyl_bessel_j(Real(bessel_j_int_data[i][0]), Real(bessel_j_int_data[i][1]));
      }

#include "libs/math/test/bessel_j_data.ipp"
      for(unsigned i = 0; i < bessel_j_data.size(); ++i)
      {
         r += boost::math::cyl_bessel_j(Real(bessel_j_data[i][0]), Real(bessel_j_data[i][1]));
      }

#include "libs/math/test/bessel_j_large_data.ipp"
      for(unsigned i = 0; i < bessel_j_large_data.size(); ++i)
      {
         r += boost::math::cyl_bessel_j(Real(bessel_j_large_data[i][0]), Real(bessel_j_large_data[i][1]));
      }

#include "libs/math/test/sph_bessel_data.ipp"
      for(unsigned i = 0; i < sph_bessel_data.size(); ++i)
      {
         r += boost::math::sph_bessel(static_cast<unsigned>(sph_bessel_data[i][0]), Real(sph_bessel_data[i][1]));
      }

      return r;
   }
   catch(const std::exception& e)
   {
      std::cout << e.what() << std::endl;
   }
   return 0;
}

template <class Real>
Real test_polynomial()
{
   static const unsigned t[] = {
      2, 3, 4, 5, 6, 7, 8 };
   Real result = 0;
   for(Real k = 2; k < 1000; ++k)
      result += boost::math::tools::evaluate_polynomial(t, k);

   return result;
}

template <class Real>
Real test_nct()
{
#define T double
#include "libs/math/test/nct.ipp"

   Real result = 0;
   for(unsigned i = 0; i < nct.size(); ++i)
   {
      try{
         result += quantile(boost::math::non_central_t_distribution<Real>(nct[i][0], nct[i][1]), nct[i][3]);
         result += cdf(boost::math::non_central_t_distribution<Real>(nct[i][0], nct[i][1]), nct[i][2]);
      }
      catch(const std::exception&)
      {}
   }
   return result;
}

extern unsigned allocation_count;

template <class Real>
void basic_allocation_test(const char* name, Real x)
{
   static const unsigned a[] = { 2, 3, 4, 5, 6, 7, 8 };
   allocation_count = 0;
   Real result = (((((a[6] * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0];
   std::cout << "Allocation count for type " << name << " = " << allocation_count << std::endl;
}

template <class Real>
void poly_allocation_test(const char* name, Real x)
{
   static const unsigned a[] = { 2, 3, 4, 5, 6, 7, 8 };
   allocation_count = 0;
   Real result = boost::math::tools::evaluate_polynomial(a, x);
   std::cout << "Allocation count for type " << name << " = " << allocation_count << std::endl;
}

template <class Real>
void time_proc(const char* name, Real (*proc)(), unsigned threads = 1)
{
   try{
      static Real total = 0;
      allocation_count = 0;
      boost::chrono::duration<double> time;
      stopwatch<boost::chrono::high_resolution_clock> c;
      total += proc();
      time = c.elapsed();
      std::cout << "Time for " << name << " = " << time << std::endl;
      std::cout << "Total allocations for " << name << " = " << allocation_count << std::endl;

      for(unsigned thread_count = 1; thread_count < threads; ++thread_count)
      {
         c.reset();
         boost::thread_group g;
         for(unsigned i = 0; i <= thread_count; ++i)
            g.create_thread(proc);
         g.join_all();
         time = c.elapsed();
         std::cout << "Time for " << name << " (" << (thread_count + 1) << " threads) = " << time << std::endl;
         std::cout << "Total allocations for " << name << " = " << allocation_count << std::endl;
      }
   }
   catch(const std::exception& e)
   {
      std::cout << e.what() << std::endl;
   }
}

using namespace boost::multiprecision;

void basic_tests();
void bessel_tests();
void poly_tests();
void nct_tests();