1 ///////////////////////////////////////////////////////////////////////////////
2 // Copyright 2012 John Maddock. Distributed under the Boost
3 // Software License, Version 1.0. (See accompanying file
4 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 #pragma warning(disable : 4244)
11 #include <boost/polygon/detail/voronoi_predicates.hpp>
12 #include <boost/polygon/detail/voronoi_structures.hpp>
13 #include <boost/polygon/detail/voronoi_ctypes.hpp>
14 #include <boost/random/mersenne_twister.hpp>
15 #include <boost/random/uniform_int_distribution.hpp>
18 #include <boost/chrono.hpp>
19 #include <boost/multiprecision/cpp_int.hpp>
22 #include <boost/multiprecision/gmp.hpp>
25 #include <boost/multiprecision/tommath.hpp>
28 #include "arithmetic_backend.hpp"
30 typedef boost::polygon::detail::point_2d
<std::int32_t> i_point
;
32 template <class Clock
>
35 typedef typename
Clock::duration duration
;
38 m_start
= Clock::now();
42 return Clock::now() - m_start
;
46 m_start
= Clock::now();
50 typename
Clock::time_point m_start
;
53 std::vector
<i_point
> points
;
54 boost::random::mt19937 gen
;
57 struct cpp_int_voronoi_traits
59 typedef std::int32_t int_type
;
60 typedef std::int64_t int_x2_type
;
61 typedef std::uint64_t uint_x2_type
;
62 typedef Big big_int_type
;
63 typedef double fpt_type
;
64 typedef boost::polygon::detail::extended_exponent_fpt
<fpt_type
> efpt_type
;
65 typedef boost::polygon::detail::ulp_comparison
<fpt_type
> ulp_cmp_type
;
66 struct to_fpt_converter_type
68 template <class B
, boost::multiprecision::expression_template_option ET
>
69 double operator()(const boost::multiprecision::number
<B
, ET
>& val
)
71 return val
.template convert_to
<double>();
73 double operator()(double val
)
77 double operator()(const efpt_type
& that
) const
81 template <class tag
, class Arg1
, class Arg2
, class Arg3
, class Arg4
>
82 double operator()(const boost::multiprecision::detail::expression
<tag
, Arg1
, Arg2
, Arg3
, Arg4
>& e
)
84 typedef typename
boost::multiprecision::detail::expression
<tag
, Arg1
, Arg2
, Arg3
, Arg4
>::result_type r_t
;
86 return r
.template convert_to
<double>();
89 struct to_efpt_converter_type
91 template <class B
, boost::multiprecision::expression_template_option ET
>
92 efpt_type
operator()(const boost::multiprecision::number
<B
, ET
>& val
)
94 return efpt_type(val
.template convert_to
<double>(), 0);
96 efpt_type
operator()(double val
)
98 return efpt_type(val
, 0);
100 template <class tag
, class Arg1
, class Arg2
, class Arg3
, class Arg4
>
101 efpt_type
operator()(const boost::multiprecision::detail::expression
<tag
, Arg1
, Arg2
, Arg3
, Arg4
>& e
)
103 typedef typename
boost::multiprecision::detail::expression
<tag
, Arg1
, Arg2
, Arg3
, Arg4
>::result_type r_t
;
105 return efpt_type(r
.template convert_to
<double>(), 0);
111 struct native_int_voronoi_traits
113 typedef std::int32_t int_type
;
114 typedef std::int64_t int_x2_type
;
115 typedef std::uint64_t uint_x2_type
;
116 typedef Big big_int_type
;
117 typedef double fpt_type
;
118 typedef boost::polygon::detail::extended_exponent_fpt
<fpt_type
> efpt_type
;
119 typedef boost::polygon::detail::ulp_comparison
<fpt_type
> ulp_cmp_type
;
120 struct to_fpt_converter_type
123 double operator()(const T
& val
) const
127 double operator()(const efpt_type
& that
) const
132 struct to_efpt_converter_type
135 efpt_type
operator()(const T
& val
) const
137 return efpt_type(val
, 0);
142 std::map
<std::string
, double> results
;
143 double min_time
= (std::numeric_limits
<double>::max
)();
145 template <class Traits
>
146 double test(const char* name
)
148 typedef boost::polygon::detail::voronoi_predicates
<Traits
> preds
;
149 typedef boost::polygon::detail::circle_event
<std::int32_t> circle_event
;
150 typedef boost::polygon::detail::site_event
<std::int32_t> site_event
;
151 typedef typename
preds::template mp_circle_formation_functor
<site_event
, circle_event
> circle_pred
;
153 boost::random::uniform_int_distribution
<> dist(0, points
.size() - 1);
157 stopwatch
<boost::chrono::high_resolution_clock
> w
;
159 for (unsigned i
= 0; i
< 10000; ++i
)
161 site_event
s1(points
[dist(gen
)]);
162 site_event
s2(points
[dist(gen
)]);
163 site_event
s3(points
[dist(gen
)]);
164 pc
.ppp(s1
, s2
, s3
, event
);
165 pc
.pps(s1
, s2
, s3
, 0, event
);
166 pc
.pss(s1
, s2
, s3
, 0, event
);
167 pc
.sss(s1
, s2
, s3
, event
);
169 double d
= boost::chrono::duration_cast
<boost::chrono::duration
<double> >(w
.elapsed()).count();
173 std::cout
<< "Time for " << std::setw(30) << std::left
<< name
<< " = " << d
<< std::endl
;
177 void generate_quickbook()
179 std::cout
<< "[table\n[[Integer Type][Relative Performance (Actual time in parenthesis)]]\n";
181 std::map
<std::string
, double>::const_iterator
i(results
.begin()), j(results
.end());
185 double rel
= i
->second
/ min_time
;
186 std::cout
<< "[[" << i
->first
<< "][" << rel
<< "(" << i
->second
<< "s)]]\n";
195 boost::random::uniform_int_distribution
<> dist((std::numeric_limits
<std::int32_t>::min
)() / 2, (std::numeric_limits
<std::int32_t>::max
)() / 2);
197 for (unsigned i
= 0; i
< 100; ++i
)
199 points
.push_back(i_point(dist(gen
), dist(gen
)));
202 test
<boost::polygon::detail::voronoi_ctype_traits
<std::int32_t> >("extended_int");
204 test
<cpp_int_voronoi_traits
<boost::multiprecision::int256_t
> >("int256_t");
205 test
<cpp_int_voronoi_traits
<boost::multiprecision::int512_t
> >("int512_t");
206 test
<cpp_int_voronoi_traits
<boost::multiprecision::int1024_t
> >("int1024_t");
208 test
<cpp_int_voronoi_traits
<boost::multiprecision::checked_int256_t
> >("checked_int256_t");
209 test
<cpp_int_voronoi_traits
<boost::multiprecision::checked_int512_t
> >("checked_int512_t");
210 test
<cpp_int_voronoi_traits
<boost::multiprecision::checked_int1024_t
> >("checked_int1024_t");
212 test
<cpp_int_voronoi_traits
<boost::multiprecision::number
<boost::multiprecision::cpp_int_backend
<>, boost::multiprecision::et_off
> > >("cpp_int");
215 test
<cpp_int_voronoi_traits
<boost::multiprecision::number
<boost::multiprecision::gmp_int
, boost::multiprecision::et_off
> > >("mpz_int");
218 test
<cpp_int_voronoi_traits
<boost::multiprecision::number
<boost::multiprecision::tommath_int
, boost::multiprecision::et_off
> > >("tom_int");
221 generate_quickbook();
223 test
<native_int_voronoi_traits
<std::int64_t> >("int64_t");
224 test
<cpp_int_voronoi_traits
<boost::multiprecision::number
<boost::multiprecision::arithmetic_backend
<std::int64_t>, boost::multiprecision::et_off
> > >("number<arithmetic_backend<std::int64_t>, et_off>");
225 //test<cpp_int_voronoi_traits<boost::multiprecision::number<boost::multiprecision::arithmetic_backend<std::int64_t>, boost::multiprecision::et_on> > >("number<arithmetic_backend<std::int64_t>, et_on>");