]> www.ginac.de Git - cln.git/blob - benchmarks/timebench2a.cc
Make GCC compiler flags default to -O
[cln.git] / benchmarks / timebench2a.cc
1 #include <cln/number.h>
2 #include <cln/io.h>
3 #include <cln/integer.h>
4 #include <cln/integer_io.h>
5 #include <cln/float.h>
6 #include <cln/real.h>
7 #include <cstdlib>
8 #include <cstring>
9 #include <cln/timing.h>
10
11 using namespace std;
12 using namespace cln;
13
14 int main (int argc, char * argv[])
15 {
16         int digits = 100;
17         int repetitions = 1;
18         while (argc >= 3) {
19                 if (!strcmp(argv[1],"-r")) {
20                         repetitions = atoi(argv[2]);
21                         argc -= 2; argv += 2;
22                         continue;
23                 }
24                 if (!strcmp(argv[1],"-n")) {
25                         digits = atoi(argv[2]);
26                         argc -= 2; argv += 2;
27                         continue;
28                 }
29                 break;
30         }
31         if (argc < 1)
32                 exit(1);
33         
34         cerr << "Number of digits: " << digits << endl;
35         cerr << "Number of repetitions: " << repetitions << endl;
36
37         float_format_t prec = float_format(digits);
38         float_format_t prec2 = float_format(digits*2);
39         cl_I pow = expt_pos(10,digits);
40         cl_I x1 = floor1((sqrt(cl_float(5,prec2))+1)/2 * expt_pos(pow,2));
41         cl_I x2 = floor1(sqrt(cl_float(3,prec)) * pow);
42         cl_I x3 = pow+1;
43
44         cerr << "multiplication" << endl;
45         { cl_I r = x1*x2;
46           { CL_TIMING;
47             for (int rep = repetitions; rep > 0; rep--)
48               { r = x1*x2; }
49           }
50           cout << r << endl << endl;
51         }
52
53         cerr << "division" << endl;
54         { cl_I_div_t qr = floor2(x1,x2);
55           { CL_TIMING;
56             for (int rep = repetitions; rep > 0; rep--)
57               { qr = floor2(x1,x2); }
58           }
59           cout << qr.quotient << endl << qr.remainder << endl << endl;
60         }
61
62         cerr << "isqrt" << endl;
63         { cl_I r = isqrt(x3);
64           { CL_TIMING;
65             for (int rep = repetitions; rep > 0; rep--)
66               { r = isqrt(x3); }
67           }
68           cout << r << endl << endl;
69         }
70
71         cerr << "gcd" << endl;
72         { cl_I r = gcd(x1,x2);
73           { CL_TIMING;
74             for (int rep = repetitions; rep > 0; rep--)
75               { r = gcd(x1,x2); }
76           }
77           cout << r << endl << endl;
78         }
79
80 }