// Copyright Jeremy Murphy 2016. // Use, modification and distribution are subject to 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 : 4224) #endif #include "../../test/table_type.hpp" #include "table_helper.hpp" #include "performance.hpp" #include #include #include #include #include #include #include #include #include #include using namespace std; template ::type> pair exec_timed_test_foo(Func f, double min_elapsed = 0.5) { double t = 0; unsigned repeats = 1; Result sum{0}; stopwatch w; do { for(unsigned count = 0; count < repeats; ++count) sum += f(); t = boost::chrono::duration_cast>(w.elapsed()).count(); if(t < min_elapsed) repeats *= 2; } while(t < min_elapsed); return {t / repeats, sum}; } template struct test_function_template { pair data; test_function_template(pair const &data) : data(data) {} template void operator()(pair const &f) const { auto result = exec_timed_test_foo(bind(f.first, data.first, data.second)); report_execution_time(result.first, string("gcd method comparison with ") + compiler_name() + string(" on ") + platform_name(), f.second, boost_name()); } }; int main() { using namespace boost::math::detail; typedef unsigned int_type; pair test_data{1836311903, 2971215073}; // 46th and 47th Fibonacci numbers. 47th is prime. typedef pair< function, string> f_test; array test_functions{{{gcd_euclidean, "gcd_euclidean"}, {gcd_binary, "gcd_binary"}}}; for_each(begin(test_functions), end(test_functions), test_function_template(test_data)); }