1 //  Copyright John Maddock 2015.
2 //  Use, modification and distribution are subject to the
3 //  Boost Software License, Version 1.0. (See accompanying file
4 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5 
6 #ifdef _MSC_VER
7 #  pragma warning (disable : 4224)
8 #endif
9 
10 #include <boost/math/special_functions/gamma.hpp>
11 #include <boost/array.hpp>
12 #include <boost/lexical_cast.hpp>
13 #include "../../test/table_type.hpp"
14 #include "table_helper.hpp"
15 #include "performance.hpp"
16 #include <iostream>
17 
main()18 int main()
19 {
20    typedef double T;
21 #define SC_(x) static_cast<double>(x)
22 #  include "test_gamma_data.ipp"
23 
24    add_data(factorials);
25    add_data(near_0);
26    add_data(near_1);
27    add_data(near_2);
28    add_data(near_m10);
29    add_data(near_m55);
30 
31    unsigned data_total = data.size();
32 
33    screen_data([](const std::vector<double>& v){  return boost::math::lgamma(v[0]);  }, [](const std::vector<double>& v){ return v[2];  });
34 
35 
36 #if defined(TEST_C99) && !defined(COMPILER_COMPARISON_TABLES)
37    screen_data([](const std::vector<double>& v){  return ::lgamma(v[0]);  }, [](const std::vector<double>& v){ return v[2];  });
38 #endif
39 #if defined(TEST_LIBSTDCXX) && !defined(COMPILER_COMPARISON_TABLES)
40    screen_data([](const std::vector<double>& v){  return std::tr1::lgamma(v[0]);  }, [](const std::vector<double>& v){ return v[2];  });
41 #endif
42 #if defined(TEST_GSL) && !defined(COMPILER_COMPARISON_TABLES)
43    screen_data([](const std::vector<double>& v){  return gsl_sf_lngamma(v[0]);  }, [](const std::vector<double>& v){ return v[2];  });
44 #endif
45 #if defined(TEST_RMATH) && !defined(COMPILER_COMPARISON_TABLES)
46    screen_data([](const std::vector<double>& v){  return lgammafn(v[0]);  }, [](const std::vector<double>& v){ return v[2];  });
47 #endif
48 
49    unsigned data_used = data.size();
50    std::string function = "lgamma[br](" + boost::lexical_cast<std::string>(data_used) + "/" + boost::lexical_cast<std::string>(data_total) + " tests selected)";
51    std::string function_short = "lgamma";
52 
53    double time = exec_timed_test([](const std::vector<double>& v){  return boost::math::lgamma(v[0]);  });
54    std::cout << time << std::endl;
55 #if !defined(COMPILER_COMPARISON_TABLES) && (defined(TEST_GSL) || defined(TEST_RMATH) || defined(TEST_C99) || defined(TEST_LIBSTDCXX))
56    report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, boost_name());
57 #endif
58    report_execution_time(time, std::string("Compiler Comparison on ") + std::string(platform_name()), function_short, compiler_name() + std::string("[br]") + boost_name());
59    //
60    // Boost again, but with promotion to long double turned off:
61    //
62 #if !defined(COMPILER_COMPARISON_TABLES)
63    if(sizeof(long double) != sizeof(double))
64    {
65       double time = exec_timed_test([](const std::vector<double>& v){  return boost::math::lgamma(v[0], boost::math::policies::make_policy(boost::math::policies::promote_double<false>()));  });
66       std::cout << time << std::endl;
67 #if !defined(COMPILER_COMPARISON_TABLES) && (defined(TEST_GSL) || defined(TEST_RMATH) || defined(TEST_C99) || defined(TEST_LIBSTDCXX))
68       report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, boost_name() + "[br]promote_double<false>");
69 #endif
70       report_execution_time(time, std::string("Compiler Comparison on ") + std::string(platform_name()), function_short, compiler_name() + std::string("[br]") + boost_name() + "[br]promote_double<false>");
71    }
72 #endif
73 
74 
75 #if defined(TEST_C99) && !defined(COMPILER_COMPARISON_TABLES)
76    time = exec_timed_test([](const std::vector<double>& v){  return ::lgamma(v[0]);  });
77    std::cout << time << std::endl;
78    report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, "math.h");
79 #endif
80 #if defined(TEST_LIBSTDCXX) && !defined(COMPILER_COMPARISON_TABLES)
81    time = exec_timed_test([](const std::vector<double>& v){  return std::tr1::lgamma(v[0]);  });
82    std::cout << time << std::endl;
83    report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, "tr1/cmath");
84 #endif
85 #if defined(TEST_GSL) && !defined(COMPILER_COMPARISON_TABLES)
86    time = exec_timed_test([](const std::vector<double>& v){  return gsl_sf_lngamma(v[0]);  });
87    std::cout << time << std::endl;
88    report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, "GSL " GSL_VERSION);
89 #endif
90 #if defined(TEST_RMATH) && !defined(COMPILER_COMPARISON_TABLES)
91    time = exec_timed_test([](const std::vector<double>& v){  return lgammafn(v[0]);  });
92    std::cout << time << std::endl;
93    report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, "Rmath "  R_VERSION_STRING);
94 #endif
95 
96    return 0;
97 }
98 
99