• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
5 
6 #include "miller_rabin_performance.hpp"
7 
8 unsigned allocation_count = 0;
9 
10 void* (*alloc_func_ptr)(size_t);
11 void* (*realloc_func_ptr)(void*, size_t, size_t);
12 void (*free_func_ptr)(void*, size_t);
13 
alloc_func(size_t n)14 void* alloc_func(size_t n)
15 {
16    ++allocation_count;
17    return (*alloc_func_ptr)(n);
18 }
19 
free_func(void * p,size_t n)20 void free_func(void* p, size_t n)
21 {
22    (*free_func_ptr)(p, n);
23 }
24 
realloc_func(void * p,size_t old,size_t n)25 void* realloc_func(void* p, size_t old, size_t n)
26 {
27    ++allocation_count;
28    return (*realloc_func_ptr)(p, old, n);
29 }
30 
31 #ifdef TEST_MPZ
test_miller_rabin_gmp()32 boost::chrono::duration<double> test_miller_rabin_gmp()
33 {
34    using namespace boost::random;
35    using namespace boost::multiprecision;
36 
37    stopwatch<boost::chrono::high_resolution_clock> c;
38 
39    independent_bits_engine<mt11213b, 256, mpz_int> gen;
40 
41    for (unsigned i = 0; i < 1000; ++i)
42    {
43       mpz_int n = gen();
44       mpz_probab_prime_p(n.backend().data(), 25);
45    }
46    return c.elapsed();
47 }
48 #endif
49 
50 std::map<std::string, double> results;
51 double                        min_time = (std::numeric_limits<double>::max)();
52 
generate_quickbook()53 void generate_quickbook()
54 {
55    std::cout << "[table\n[[Integer Type][Relative Performance (Actual time in parenthesis)]]\n";
56 
57    std::map<std::string, double>::const_iterator i(results.begin()), j(results.end());
58 
59    while (i != j)
60    {
61       double rel = i->second / min_time;
62       std::cout << "[[" << i->first << "][" << rel << "(" << i->second << "s)]]\n";
63       ++i;
64    }
65 
66    std::cout << "]\n";
67 }
68 
main()69 int main()
70 {
71    test01();
72    test02();
73    test03();
74    test04();
75    test05();
76    test06();
77    test07();
78    test08();
79    test09();
80    test10();
81    test11();
82    test12();
83 
84    generate_quickbook();
85 
86    return 0;
87 }
88