]> www.ginac.de Git - cln.git/blob - benchmarks/timebench2a.cc
- autoconf/aclocal.m4 (CL_CANONICAL_HOST): Added missing changequote
[cln.git] / benchmarks / timebench2a.cc
1 #include <cl_number.h>
2 #include <cl_io.h>
3 #include <cl_integer.h>
4 #include <cl_integer_io.h>
5 #include <cl_float.h>
6 #include <cl_real.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <cl_timing.h>
10
11 int main (int argc, char * argv[])
12 {
13         int digits = 100;
14         int repetitions = 1;
15         while (argc >= 3) {
16                 if (!strcmp(argv[1],"-r")) {
17                         repetitions = atoi(argv[2]);
18                         argc -= 2; argv += 2;
19                         continue;
20                 }
21                 if (!strcmp(argv[1],"-n")) {
22                         digits = atoi(argv[2]);
23                         argc -= 2; argv += 2;
24                         continue;
25                 }
26                 break;
27         }
28         if (argc < 1)
29                 exit(1);
30
31         fprint(cl_stderr, "Number of digits: ");
32         fprintdecimal(cl_stderr, digits);
33         fprint(cl_stderr, "\n");
34         fprint(cl_stderr, "Number of repetitions: ");
35         fprintdecimal(cl_stderr, repetitions);
36         fprint(cl_stderr, "\n");
37
38         cl_float_format_t prec = cl_float_format(digits);
39         cl_float_format_t prec2 = cl_float_format(digits*2);
40         cl_I pow = expt_pos(10,digits);
41         cl_I x1 = floor1((sqrt(cl_float(5,prec2))+1)/2 * expt_pos(pow,2));
42         cl_I x2 = floor1(sqrt(cl_float(3,prec)) * pow);
43         cl_I x3 = pow+1;
44
45         fprint(cl_stderr, "multiplication\n");
46         { cl_I r = x1*x2;
47           { CL_TIMING;
48             for (int rep = repetitions; rep > 0; rep--)
49               { r = x1*x2; }
50           }
51           cout << r << endl << endl;
52         }
53
54         fprint(cl_stderr, "division\n");
55         { cl_I_div_t qr = floor2(x1,x2);
56           { CL_TIMING;
57             for (int rep = repetitions; rep > 0; rep--)
58               { qr = floor2(x1,x2); }
59           }
60           cout << qr.quotient << endl << qr.remainder << endl << endl;
61         }
62
63         fprint(cl_stderr, "isqrt\n");
64         { cl_I r = isqrt(x3);
65           { CL_TIMING;
66             for (int rep = repetitions; rep > 0; rep--)
67               { r = isqrt(x3); }
68           }
69           cout << r << endl << endl;
70         }
71
72         fprint(cl_stderr, "gcd\n");
73         { cl_I r = gcd(x1,x2);
74           { CL_TIMING;
75             for (int rep = repetitions; rep > 0; rep--)
76               { r = gcd(x1,x2); }
77           }
78           cout << r << endl << endl;
79         }
80
81 }