]> www.ginac.de Git - cln.git/blob - benchmarks/timebench2a.LiDIA.cc
Remove the conversion step .tex -> .texi.
[cln.git] / benchmarks / timebench2a.LiDIA.cc
1 #include <LiDIA/bigint.h>
2 #include <LiDIA/bigfloat.h>
3 #include <LiDIA/timer.h>
4 #include <cstdlib>
5 #include <cstring>
6
7 int main (int argc, char * argv[])
8 {
9         int digits = 100;
10         int repetitions = 1;
11         while (argc >= 3) {
12                 if (!strcmp(argv[1],"-r")) {
13                         repetitions = atoi(argv[2]);
14                         argc -= 2; argv += 2;
15                         continue;
16                 }
17                 if (!strcmp(argv[1],"-n")) {
18                         digits = atoi(argv[2]);
19                         argc -= 2; argv += 2;
20                         continue;
21                 }
22                 break;
23         }
24         if (argc < 1)
25                 exit(1);
26
27         cerr << "Number of digits: " << digits << "\n";
28         cerr << "Number of repetitions: " << repetitions << "\n";
29
30         bigint pow; power(pow, (bigint)10,digits);
31         bigfloat::precision(digits*2);
32         bigint x1; truncate(x1, ((sqrt((bigfloat)5)+1)/2) * (pow*pow));
33         bigfloat::precision(digits);
34         bigint x2; truncate(x2, sqrt((bigfloat)3) * pow);
35         bigint x3 = pow+1;
36
37         cerr << "multiplication\n";
38         { bigint r = x1*x2;
39           { timer t; t.set_print_mode(0); t.start_timer();
40             for (int rep = repetitions; rep > 0; rep--)
41               { bigint r = x1*x2; }
42             t.stop_timer(); cerr << t << endl;
43           }
44           cout << r << endl << endl;
45         }
46
47         cerr << "division\n";
48         { bigint q; bigint r; div_rem(q,r, x1,x2);
49           { timer t; t.set_print_mode(0); t.start_timer();
50             for (int rep = repetitions; rep > 0; rep--)
51               { bigint q; bigint r; div_rem(q,r, x1,x2); }
52             t.stop_timer(); cerr << t << endl;
53           }
54           cout << q << endl << r << endl << endl;
55         }
56
57         cerr << "isqrt\n";
58         { bigint r; sqrt(r, x3);
59           { timer t; t.set_print_mode(0); t.start_timer();
60             for (int rep = repetitions; rep > 0; rep--)
61               { bigint r; sqrt(r, x3); }
62             t.stop_timer(); cerr << t << endl;
63           }
64           cout << r << endl << endl;
65         }
66
67         cerr << "gcd\n";
68         { bigint r = gcd(x1,x2);
69           { timer t; t.set_print_mode(0); t.start_timer();
70             for (int rep = repetitions; rep > 0; rep--)
71               { bigint r = gcd(x1,x2); }
72             t.stop_timer(); cerr << t << endl;
73           }
74           cout << r << endl << endl;
75         }
76
77 }