test_log1p.cpp 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. #ifdef _MSC_VER
  6. # pragma warning (disable : 4224)
  7. #endif
  8. #include <boost/math/special_functions/log1p.hpp>
  9. #include <boost/array.hpp>
  10. #include <boost/lexical_cast.hpp>
  11. #include "../../test/table_type.hpp"
  12. #include "table_helper.hpp"
  13. #include "performance.hpp"
  14. #include <iostream>
  15. int main()
  16. {
  17. typedef double T;
  18. #define SC_(x) static_cast<double>(x)
  19. # include "../../test/log1p_expm1_data.ipp"
  20. add_data(log1p_expm1_data);
  21. unsigned data_total = data.size();
  22. screen_data([](const std::vector<double>& v){ return boost::math::log1p(v[0]); }, [](const std::vector<double>& v){ return v[1]; });
  23. #if defined(TEST_C99) && !defined(COMPILER_COMPARISON_TABLES)
  24. screen_data([](const std::vector<double>& v){ return ::log1p(v[0]); }, [](const std::vector<double>& v){ return v[1]; });
  25. #endif
  26. #ifdef TEST_LIBSTDCXX && !defined(COMPILER_COMPARISON_TABLES)
  27. screen_data([](const std::vector<double>& v){ return std::tr1::log1p(v[0]); }, [](const std::vector<double>& v){ return v[1]; });
  28. #endif
  29. unsigned data_used = data.size();
  30. std::string function = "log1p[br](" + boost::lexical_cast<std::string>(data_used)+"/" + boost::lexical_cast<std::string>(data_total)+" tests selected)";
  31. std::string function_short = "log1p";
  32. double time = exec_timed_test([](const std::vector<double>& v){ return boost::math::log1p(v[0]); });
  33. std::cout << time << std::endl;
  34. #if !defined(COMPILER_COMPARISON_TABLES) && (defined(TEST_GSL) || defined(TEST_RMATH) || defined(TEST_C99) || defined(TEST_LIBSTDCXX))
  35. report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, boost_name());
  36. #endif
  37. report_execution_time(time, std::string("Compiler Comparison on ") + std::string(platform_name()), function_short, compiler_name() + std::string("[br]") + boost_name());
  38. //
  39. // Boost again, but with promotion to long double turned off:
  40. //
  41. #if !defined(COMPILER_COMPARISON_TABLES)
  42. if(sizeof(long double) != sizeof(double))
  43. {
  44. double time = exec_timed_test([](const std::vector<double>& v){ return boost::math::log1p(v[0], boost::math::policies::make_policy(boost::math::policies::promote_double<false>())); });
  45. std::cout << time << std::endl;
  46. #if !defined(COMPILER_COMPARISON_TABLES) && (defined(TEST_GSL) || defined(TEST_RMATH) || defined(TEST_C99) || defined(TEST_LIBSTDCXX))
  47. 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>");
  48. #endif
  49. 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>");
  50. }
  51. #endif
  52. #if defined(TEST_C99) && !defined(COMPILER_COMPARISON_TABLES)
  53. time = exec_timed_test([](const std::vector<double>& v){ return ::log1p(v[0]); });
  54. std::cout << time << std::endl;
  55. report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, "math.h");
  56. #endif
  57. #if defined(TEST_LIBSTDCXX) && !defined(COMPILER_COMPARISON_TABLES)
  58. time = exec_timed_test([](const std::vector<double>& v){ return std::tr1::log1p(v[0]); });
  59. std::cout << time << std::endl;
  60. report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, "tr1/cmath");
  61. #endif
  62. return 0;
  63. }