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 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
|
///////////////////////////////////////////////////////////////////////////////
// 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 <boost/polygon/detail/voronoi_predicates.hpp>
#include <boost/polygon/detail/voronoi_structures.hpp>
#include <boost/polygon/detail/skeleton_predicates.hpp>
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/uniform_int_distribution.hpp>
#include <vector>
#include <map>
#include <boost/chrono.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#ifdef TEST_GMP
#include <boost/multiprecision/gmp.hpp>
#endif
#ifdef TEST_TOMMATH
#include <boost/multiprecision/tommath.hpp>
#endif
#include "arithmetic_backend.hpp"
typedef boost::polygon::detail::point_2d<boost::int32_t> i_point;
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;
};
std::vector<i_point> points;
boost::random::mt19937 gen;
template <class Big>
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<fpt_type> efpt_type;
typedef boost::polygon::detail::ulp_comparison<fpt_type> ulp_cmp_type;
struct to_fpt_converter_type
{
template <class B, boost::multiprecision::expression_template_option ET>
double operator ()(const boost::multiprecision::number<B, ET>& val)
{
return val.template convert_to<double>();
}
double operator ()(double val)
{
return val;
}
double operator()(const efpt_type& that) const
{
return that.d();
}
template <class tag, class Arg1, class Arg2, class Arg3, class Arg4>
double operator()(const boost::multiprecision::detail::expression<tag, Arg1, Arg2, Arg3, Arg4>& e)
{
typedef typename boost::multiprecision::detail::expression<tag, Arg1, Arg2, Arg3, Arg4>::result_type r_t;
r_t r(e);
return r.template convert_to<double>();
}
};
struct to_efpt_converter_type
{
template <class B, boost::multiprecision::expression_template_option ET>
efpt_type operator ()(const boost::multiprecision::number<B, ET>& val)
{
return efpt_type(val.template convert_to<double>(), 0);
}
efpt_type operator ()(double val)
{
return efpt_type(val, 0);
}
template <class tag, class Arg1, class Arg2, class Arg3, class Arg4>
double operator()(const boost::multiprecision::detail::expression<tag, Arg1, Arg2, Arg3, Arg4>& e)
{
typedef typename boost::multiprecision::detail::expression<tag, Arg1, Arg2, Arg3, Arg4>::result_type r_t;
r_t r(e);
return efpt_type(r.template convert_to<double>(), 0);
}
};
};
template <class Big>
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<fpt_type> efpt_type;
typedef boost::polygon::detail::ulp_comparison<fpt_type> ulp_cmp_type;
struct to_fpt_converter_type
{
template <class T>
double operator ()(const T& val)const
{
return val;
}
double operator()(const efpt_type& that) const
{
return that.d();
}
};
struct to_efpt_converter_type
{
template <class T>
efpt_type operator ()(const T& val)const
{
return efpt_type(val, 0);
}
};
};
std::map<std::string, double> results;
double min_time = (std::numeric_limits<double>::max)();
template <class Traits>
double test(const char* name)
{
typedef boost::polygon::detail::voronoi_predicates<Traits> preds;
typedef boost::polygon::detail::circle_event<boost::int32_t> circle_event;
typedef boost::polygon::detail::site_event<boost::int32_t> site_event;
typedef typename preds::template mp_circle_formation_functor<site_event, circle_event> circle_pred;
boost::random::uniform_int_distribution<> dist(0, points.size() - 1);
circle_pred pc;
circle_event event;
stopwatch<boost::chrono::high_resolution_clock> 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<boost::chrono::duration<double> >(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<std::string, double>::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<boost::int32_t>::min)() / 2, (std::numeric_limits<boost::int32_t>::max)() / 2);
for(unsigned i = 0; i < 100; ++i)
{
points.push_back(i_point(dist(gen), dist(gen)));
}
test<boost::polygon::detail::voronoi_ctype_traits<boost::int32_t> >("extended_int");
test<cpp_int_voronoi_traits<boost::multiprecision::int256_t> >("int256_t");
test<cpp_int_voronoi_traits<boost::multiprecision::int512_t> >("int512_t");
test<cpp_int_voronoi_traits<boost::multiprecision::int1024_t> >("int1024_t");
test<cpp_int_voronoi_traits<boost::multiprecision::checked_int256_t> >("checked_int256_t");
test<cpp_int_voronoi_traits<boost::multiprecision::checked_int512_t> >("checked_int512_t");
test<cpp_int_voronoi_traits<boost::multiprecision::checked_int1024_t> >("checked_int1024_t");
test<cpp_int_voronoi_traits<boost::multiprecision::number<boost::multiprecision::cpp_int_backend<>, boost::multiprecision::et_off> > >("cpp_int");
#ifdef TEST_GMP
test<cpp_int_voronoi_traits<boost::multiprecision::number<boost::multiprecision::gmp_int, boost::multiprecision::et_off> > >("mpz_int");
#endif
#ifdef TEST_TOMMATH
test<cpp_int_voronoi_traits<boost::multiprecision::number<boost::multiprecision::tommath_int, boost::multiprecision::et_off> > >("tom_int");
#endif
generate_quickbook();
test<native_int_voronoi_traits<boost::int64_t> >("int64_t");
test<cpp_int_voronoi_traits<boost::multiprecision::number<boost::multiprecision::arithmetic_backend<boost::int64_t>, boost::multiprecision::et_off> > >("number<arithmetic_backend<boost::int64_t>, et_off>");
//test<cpp_int_voronoi_traits<boost::multiprecision::number<boost::multiprecision::arithmetic_backend<boost::int64_t>, boost::multiprecision::et_on> > >("number<arithmetic_backend<boost::int64_t>, et_on>");
return 0;
}
|