1 #include <iostream>
2 #include <cstdlib>
3 
4 #include <recint/recint.h>
5 #include <givaro/givtimer.h>
6 #include <givaro/givinteger.h>
7 
8 #if not defined(STD_RECINT_SIZE)
9 #define STD_RECINT_SIZE 8
10 #endif
11 
12 #if not defined(LOOPS)
13 #define LOOPS 1000000
14 #endif
15 
16 #define ALEA_MAX  64
17 #define ALEA_MASK 63
18 
19 using namespace RecInt;
20 
main(int argc,char ** argv)21 int main(int argc, char ** argv)
22 {
23     size_t nbloops = static_cast<size_t>((argc > 1)? atoi(argv[1]) : LOOPS);
24     //    std::cerr << "nbloops: " << nbloops << std::endl;
25 
26     ruint<STD_RECINT_SIZE> a[ALEA_MAX], d[ALEA_MAX];
27     mpz_class b[ALEA_MAX], c[ALEA_MAX];
28     Givaro::Timer tim,gmp;
29 
30 
31     // Randomness
32     for (unsigned int i = 0; i < ALEA_MAX; i++) {
33         rand(a[i]);
34         ruint_to_mpz(b[i],a[i]);
35     }
36 
37     // Main loop
38     tim.clear(); tim.start();
39     for (unsigned int l = 0; l < nbloops; l++) {
40         d[l & ALEA_MASK] = a[l & ALEA_MASK];
41         d[l & ALEA_MASK] *= a[l & ALEA_MASK];
42     }
43     tim.stop();
44 
45     // Main loop
46     gmp.clear(); gmp.start();
47     for (unsigned int l = 0; l < nbloops; l++) {
48         c[l & ALEA_MASK] = b[l & ALEA_MASK];
49         c[l & ALEA_MASK] *= b[l & ALEA_MASK];
50     }
51     gmp.stop();
52 
53     ruint<STD_RECINT_SIZE> module; rand(module);
54 
55     // -----------
56     // Standard output for benchmark - Alexis Breust 2014/12/11
57     std::cout
58     << "SIZE: " << STD_RECINT_SIZE
59     << " Time: " << tim.usertime() << ' ' << gmp.usertime()
60     << " Mflops: " << std::scientific << (double(nbloops))/tim.usertime()/1000.0/1000.0 << ' ' << (double(nbloops))/gmp.usertime()/1000.0/1000.0
61     << ' ' << a[(int)(module)& ALEA_MASK] << ' ' << b[(int)(module)& ALEA_MASK] << std::endl ;
62 
63     return 0;
64 }
65 
66 /* -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
67 // vim:sts=4:sw=4:ts=4:et:sr:cino=>s,f0,{0,g0,(0,\:0,t0,+0,=s
68