/////////////////////////////////////////////////////////////////////////////// // Copyright 2012 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_0.txt) #ifdef _MSC_VER #pragma warning(disable : 4244) #endif #include #include #include #include #include #include #include #include #include #ifdef TEST_GMP #include #endif #ifdef TEST_TOMMATH #include #endif #include "arithmetic_backend.hpp" typedef boost::polygon::detail::point_2d i_point; template 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; }; std::vector points; boost::random::mt19937 gen; template struct cpp_int_voronoi_traits { typedef boost::int32_t int_type; typedef boost::int64_t int_x2_type; typedef boost::uint64_t uint_x2_type; typedef Big big_int_type; typedef double fpt_type; typedef boost::polygon::detail::extended_exponent_fpt efpt_type; typedef boost::polygon::detail::ulp_comparison ulp_cmp_type; struct to_fpt_converter_type { template double operator()(const boost::multiprecision::number& val) { return val.template convert_to(); } double operator()(double val) { return val; } double operator()(const efpt_type& that) const { return that.d(); } template double operator()(const boost::multiprecision::detail::expression& e) { typedef typename boost::multiprecision::detail::expression::result_type r_t; r_t r(e); return r.template convert_to(); } }; struct to_efpt_converter_type { template efpt_type operator()(const boost::multiprecision::number& val) { return efpt_type(val.template convert_to(), 0); } efpt_type operator()(double val) { return efpt_type(val, 0); } template double operator()(const boost::multiprecision::detail::expression& e) { typedef typename boost::multiprecision::detail::expression::result_type r_t; r_t r(e); return efpt_type(r.template convert_to(), 0); } }; }; template struct native_int_voronoi_traits { typedef boost::int32_t int_type; typedef boost::int64_t int_x2_type; typedef boost::uint64_t uint_x2_type; typedef Big big_int_type; typedef double fpt_type; typedef boost::polygon::detail::extended_exponent_fpt efpt_type; typedef boost::polygon::detail::ulp_comparison ulp_cmp_type; struct to_fpt_converter_type { template double operator()(const T& val) const { return val; } double operator()(const efpt_type& that) const { return that.d(); } }; struct to_efpt_converter_type { template efpt_type operator()(const T& val) const { return efpt_type(val, 0); } }; }; std::map results; double min_time = (std::numeric_limits::max)(); template double test(const char* name) { typedef boost::polygon::detail::voronoi_predicates preds; typedef boost::polygon::detail::circle_event circle_event; typedef boost::polygon::detail::site_event site_event; typedef typename preds::template mp_circle_formation_functor circle_pred; boost::random::uniform_int_distribution<> dist(0, points.size() - 1); circle_pred pc; circle_event event; stopwatch w; for (unsigned i = 0; i < 10000; ++i) { site_event s1(points[dist(gen)]); site_event s2(points[dist(gen)]); site_event s3(points[dist(gen)]); pc.ppp(s1, s2, s3, event); pc.pps(s1, s2, s3, 0, event); pc.pss(s1, s2, s3, 0, event); pc.sss(s1, s2, s3, event); } double d = boost::chrono::duration_cast >(w.elapsed()).count(); if (d < min_time) min_time = d; results[name] = d; std::cout << "Time for " << std::setw(30) << std::left << name << " = " << d << std::endl; return d; } void generate_quickbook() { std::cout << "[table\n[[Integer Type][Relative Performance (Actual time in parenthesis)]]\n"; std::map::const_iterator i(results.begin()), j(results.end()); while (i != j) { double rel = i->second / min_time; std::cout << "[[" << i->first << "][" << rel << "(" << i->second << "s)]]\n"; ++i; } std::cout << "]\n"; } int main() { boost::random::uniform_int_distribution<> dist((std::numeric_limits::min)() / 2, (std::numeric_limits::max)() / 2); for (unsigned i = 0; i < 100; ++i) { points.push_back(i_point(dist(gen), dist(gen))); } test >("extended_int"); test >("int256_t"); test >("int512_t"); test >("int1024_t"); test >("checked_int256_t"); test >("checked_int512_t"); test >("checked_int1024_t"); test, boost::multiprecision::et_off> > >("cpp_int"); #ifdef TEST_GMP test > >("mpz_int"); #endif #ifdef TEST_TOMMATH test > >("tom_int"); #endif generate_quickbook(); test >("int64_t"); test, boost::multiprecision::et_off> > >("number, et_off>"); //test, boost::multiprecision::et_on> > >("number, et_on>"); return 0; }