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 https://www.boost.org/LICENSE_1_0.txt
6 #define BOOST_CHRONO_HEADER_ONLY
8 #if !defined(TEST_MPZ) && !defined(TEST_TOMMATH) && !defined(TEST_CPP_INT)
15 #include <boost/multiprecision/gmp.hpp>
18 #include <boost/multiprecision/tommath.hpp>
21 #include <boost/multiprecision/cpp_int.hpp>
23 #include <boost/multiprecision/miller_rabin.hpp>
24 #include <boost/chrono.hpp>
25 #include <boost/random.hpp>
28 template <class Clock>
31 typedef typename Clock::duration duration;
34 m_start = Clock::now();
38 return Clock::now() - m_start;
42 m_start = Clock::now();
46 typename Clock::time_point m_start;
49 extern unsigned allocation_count;
51 extern std::map<std::string, double> results;
52 extern double min_time;
54 template <class IntType>
55 boost::chrono::duration<double> test_miller_rabin(const char* name)
57 using namespace boost::random;
59 stopwatch<boost::chrono::high_resolution_clock> c;
61 independent_bits_engine<mt11213b, 256, IntType> gen;
63 // We must use a different generator for the tests and number generation, otherwise
64 // we get false positives.
67 unsigned result_count = 0;
69 for (unsigned i = 0; i < 1000; ++i)
72 if (boost::multiprecision::miller_rabin_test(n, 25, gen2))
75 boost::chrono::duration<double> t = c.elapsed();
80 std::cout << "Time for " << std::setw(30) << std::left << name << " = " << d << std::endl;
81 std::cout << "Number of primes found = " << result_count << std::endl;
85 boost::chrono::duration<double> test_miller_rabin_gmp();