]> www.ginac.de Git - cln.git/blob - benchmarks/timebench2b.LiDIA.cc
* cln.pc.in: Fix typo.
[cln.git] / benchmarks / timebench2b.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 (except for pi,euler,e): " << repetitions << "\n";
29
30         bigfloat::precision(digits);
31         bigfloat x1 = sqrt((bigfloat)2);
32         bigfloat x2 = sqrt((bigfloat)3);
33         bigfloat x3 = log((bigfloat)2);
34
35         cerr << "multiplication\n";
36         { bigfloat r = x1*x2;
37           { timer t; t.set_print_mode(0); t.start_timer();
38             for (int rep = repetitions; rep > 0; rep--)
39               { r = x1*x2; }
40             t.stop_timer(); cerr << t << endl;
41           }
42           cout << r << endl << endl;
43         }
44
45         cerr << "sqrt\n";
46         { bigfloat r = sqrt(x3);
47           { timer t; t.set_print_mode(0); t.start_timer();
48             for (int rep = repetitions; rep > 0; rep--)
49               { r = sqrt(x3); }
50             t.stop_timer(); cerr << t << endl;
51           }
52           cout << r << endl << endl;
53         }
54
55         cerr << "pi\n";
56         { bigfloat r;
57           { timer t; t.set_print_mode(0); t.start_timer();
58             r = Pi();
59             t.stop_timer(); cerr << t << endl;
60           }
61           cout << r << endl << endl;
62         }
63
64         cerr << "eulerconst\n";
65         { bigfloat r;
66           { timer t; t.set_print_mode(0); t.start_timer();
67             r = Euler();
68             t.stop_timer(); cerr << t << endl;
69           }
70           cout << r << endl << endl;
71         }
72
73         cerr << "e\n";
74         { bigfloat r;
75           { timer t; t.set_print_mode(0); t.start_timer();
76             r = E();
77             t.stop_timer(); cerr << t << endl;
78           }
79           cout << r << endl << endl;
80         }
81
82         cerr << "exp\n";
83         { bigfloat r = exp(-x1);
84           { timer t; t.set_print_mode(0); t.start_timer();
85             for (int rep = repetitions; rep > 0; rep--)
86               { r = exp(-x1); }
87             t.stop_timer(); cerr << t << endl;
88           }
89           cout << r << endl << endl;
90         }
91
92         cerr << "log\n";
93         { bigfloat r = log(x2);
94           { timer t; t.set_print_mode(0); t.start_timer();
95             for (int rep = repetitions; rep > 0; rep--)
96               { r = log(x2); }
97             t.stop_timer(); cerr << t << endl;
98           }
99           cout << r << endl << endl;
100         }
101
102         cerr << "sin\n";
103         { bigfloat r = sin(5*x1);
104           { timer t; t.set_print_mode(0); t.start_timer();
105             for (int rep = repetitions; rep > 0; rep--)
106               { r = sin(5*x1); }
107             t.stop_timer(); cerr << t << endl;
108           }
109           cout << r << endl << endl;
110         }
111
112         cerr << "cos\n";
113         { bigfloat r = cos(5*x1);
114           { timer t; t.set_print_mode(0); t.start_timer();
115             for (int rep = repetitions; rep > 0; rep--)
116               { r = cos(5*x1); }
117             t.stop_timer(); cerr << t << endl;
118           }
119           cout << r << endl << endl;
120         }
121
122         cerr << "asin\n";
123         { bigfloat r = asin(x3);
124           { timer t; t.set_print_mode(0); t.start_timer();
125             for (int rep = repetitions; rep > 0; rep--)
126               { r = asin(x3); }
127             t.stop_timer(); cerr << t << endl;
128           }
129           cout << r << endl << endl;
130         }
131
132         cerr << "acos\n";
133         { bigfloat r = acos(x3);
134           { timer t; t.set_print_mode(0); t.start_timer();
135             for (int rep = repetitions; rep > 0; rep--)
136               { r = acos(x3); }
137             t.stop_timer(); cerr << t << endl;
138           }
139           cout << r << endl << endl;
140         }
141
142         cerr << "atan\n";
143         { bigfloat r = atan(x3);
144           { timer t; t.set_print_mode(0); t.start_timer();
145             for (int rep = repetitions; rep > 0; rep--)
146               { r = atan(x3); }
147             t.stop_timer(); cerr << t << endl;
148           }
149           cout << r << endl << endl;
150         }
151
152         cerr << "sinh\n";
153         { bigfloat r = sinh(x2);
154           { timer t; t.set_print_mode(0); t.start_timer();
155             for (int rep = repetitions; rep > 0; rep--)
156               { r = sinh(x2); }
157             t.stop_timer(); cerr << t << endl;
158           }
159           cout << r << endl << endl;
160         }
161
162         cerr << "cosh\n";
163         { bigfloat r = cosh(x2);
164           { timer t; t.set_print_mode(0); t.start_timer();
165             for (int rep = repetitions; rep > 0; rep--)
166               { r = cosh(x2); }
167             t.stop_timer(); cerr << t << endl;
168           }
169           cout << r << endl << endl;
170         }
171
172         cerr << "asinh\n";
173         { bigfloat r = asinh(x3);
174           { timer t; t.set_print_mode(0); t.start_timer();
175             for (int rep = repetitions; rep > 0; rep--)
176               { r = asinh(x3); }
177             t.stop_timer(); cerr << t << endl;
178           }
179           cout << r << endl << endl;
180         }
181
182         cerr << "acosh\n";
183         { bigfloat r = acosh(1+x3);
184           { timer t; t.set_print_mode(0); t.start_timer();
185             for (int rep = repetitions; rep > 0; rep--)
186               { r = acosh(1+x3); }
187             t.stop_timer(); cerr << t << endl;
188           }
189           cout << r << endl << endl;
190         }
191
192         cerr << "atanh\n";
193         { bigfloat r = atanh(x3);
194           { timer t; t.set_print_mode(0); t.start_timer();
195             for (int rep = repetitions; rep > 0; rep--)
196               { r = atanh(x3); }
197             t.stop_timer(); cerr << t << endl;
198           }
199           cout << r << endl << endl;
200         }
201
202 }