// Boost.Polygon library voronoi_fixed_int_test.cpp file // Copyright Andrii Sydorchuk 2010-2012. // 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) // See http://www.boost.org for updates, documentation, and revision history. #include #include #include #include #include #define BOOST_TEST_MODULE benchmark_test #include #include #include #include #include "boost/multiprecision/fixed_int.hpp" using namespace boost::multiprecision; #include "boost/polygon/detail/voronoi_ctypes.hpp" #include "boost/polygon/voronoi_builder.hpp" #include "boost/polygon/voronoi_diagram.hpp" using namespace boost::polygon; struct boost_multiprecision_fpt_converter { template double operator()(const T& that) const { return static_cast(that); } double operator()(const mp_int256_t& that) const { return that.convert_to(); } double operator()(const boost::polygon::detail::extended_exponent_fpt& that) const { return that.d(); } }; // This one is not used for voronoi of points. struct dummy_efpt_converter { boost::polygon::detail::extended_exponent_fpt operator()(const mp_int256_t& that) const { return boost::polygon::detail::extended_exponent_fpt(0.0); } }; struct voronoi_user_traits { typedef int int_type; typedef unsigned int uint_type; typedef __int64 int_x2_type; typedef unsigned __int64 uint_x2_type; typedef mp_int256_t 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; typedef boost_multiprecision_fpt_converter to_fpt_converter_type; typedef dummy_efpt_converter to_efpt_converter_type; enum { ULPS = 64 }; }; typedef boost::mpl::list test_types; const char *BENCHMARK_FILE = "voronoi_benchmark.txt"; boost::mt19937 gen(static_cast(time(NULL))); boost::timer timer; // Voronoi builder that uses boost multiprecision fixed int. voronoi_builder VB; // Voronoi builder that uses internal fixed int type. //voronoi_builder VB; BOOST_AUTO_TEST_CASE_TEMPLATE(benchmark_test_random, T, test_types) { typedef T coordinate_type; typedef typename boost::polygon::detail::point_2d point_type; voronoi_diagram test_output, test_output1; std::ofstream bench_file(BENCHMARK_FILE, std::ios_base::out | std::ios_base::app); bench_file << "Voronoi Benchmark Test (time in seconds):" << std::endl; bench_file << "| Number of points | Number of tests | Time per one test |" << std::endl; bench_file << std::setiosflags(std::ios::right | std::ios::fixed) << std::setprecision(6); #ifdef NDEBUG int max_points = 100000; #else int max_points = 100; #endif std::vector points; coordinate_type x, y; for (int num_points = 10; num_points <= max_points; num_points *= 10) { points.resize(num_points); timer.restart(); int num_tests = max_points / num_points; for (int cur = 0; cur < num_tests; cur++) { test_output.clear(); test_output1.clear(); for (int cur_point = 0; cur_point < num_points; cur_point++) { x = static_cast(gen()); y = static_cast(gen()); points[cur_point] = point_type(x, y); } VB.insert_points(points.begin(), points.end()); VB.construct(&test_output); VB.clear(); } double elapsed_time = timer.elapsed(); double time_per_test = elapsed_time / num_tests; bench_file << "| " << std::setw(16) << num_points << " "; bench_file << "| " << std::setw(15) << num_tests << " "; bench_file << "| " << std::setw(17) << time_per_test << " "; bench_file << "| " << std::endl; } bench_file.close(); }