]> www.ginac.de Git - cln.git/blob - benchmarks/timebench2b.cc
Fix hack from 2008-01-20 that broke on ARM.
[cln.git] / benchmarks / timebench2b.cc
1 #include <cln/number.h>
2 #include <cln/io.h>
3 #include <cln/integer.h>
4 #include <cln/float.h>
5 #include <cln/float_io.h>
6 #include <cln/real.h>
7 #include <cln/real_io.h>
8 #include <cln/complex.h>
9 #include <cln/complex_io.h>
10 #include <cstdlib>
11 #include <cstring>
12 #include <cln/timing.h>
13
14 using namespace std;
15 using namespace cln;
16
17 int main (int argc, char * argv[])
18 {
19         int digits = 100;
20         int repetitions = 1;
21         while (argc >= 3) {
22                 if (!strcmp(argv[1],"-r")) {
23                         repetitions = atoi(argv[2]);
24                         argc -= 2; argv += 2;
25                         continue;
26                 }
27                 if (!strcmp(argv[1],"-n")) {
28                         digits = atoi(argv[2]);
29                         argc -= 2; argv += 2;
30                         continue;
31                 }
32                 break;
33         }
34         if (argc < 1)
35                 exit(1);
36
37         cerr << "Number of digits: " << digits << endl;
38         cerr << "Number of repetitions (except for pi,euler,e): " << repetitions << endl;
39
40         float_format_t prec = float_format(digits);
41         cl_F x1 = sqrt(cl_float(2,prec));
42         cl_F x2 = sqrt(cl_float(3,prec));
43         cl_F x3 = The(cl_F)(log(cl_float(2,prec)));
44
45         cerr << "multiplication" << endl;
46         { cl_F 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         cerr << "sqrt" << endl;
55         { cl_F r = sqrt(x3);
56           { CL_TIMING;
57             for (int rep = repetitions; rep > 0; rep--)
58               { r = sqrt(x3); }
59           }
60           cout << r << endl << endl;
61         }
62
63         cerr << "pi" << endl;
64         { cl_F r;
65           { CL_TIMING; r = pi(prec); }
66           cout << r << endl << endl;
67         }
68
69         cerr << "eulerconst" << endl;
70         { cl_F r;
71           { CL_TIMING; r = eulerconst(prec); }
72           cout << r << endl << endl;
73         }
74
75         cerr << "e" << endl;
76         { cl_F r;
77           { CL_TIMING; r = exp1(prec); }
78           cout << r << endl << endl;
79         }
80
81         cerr << "exp" << endl;
82         { cl_F r = exp(-x1);
83           { CL_TIMING;
84             for (int rep = repetitions; rep > 0; rep--)
85               { r = exp(-x1); }
86           }
87           cout << r << endl << endl;
88         }
89
90         cerr << "log" << endl;
91         { cl_N r = log(x2);
92           { CL_TIMING;
93             for (int rep = repetitions; rep > 0; rep--)
94               { r = log(x2); }
95           }
96           cout << r << endl << endl;
97         }
98
99         cerr << "sin" << endl;
100         { cl_R r = sin(5*x1);
101           { CL_TIMING;
102             for (int rep = repetitions; rep > 0; rep--)
103               { r = sin(5*x1); }
104           }
105           cout << r << endl << endl;
106         }
107
108         cerr << "cos" << endl;
109         { cl_R r = cos(5*x1);
110           { CL_TIMING;
111             for (int rep = repetitions; rep > 0; rep--)
112               { r = cos(5*x1); }
113           }
114           cout << r << endl << endl;
115         }
116
117         cerr << "asin" << endl;
118         { cl_N r = asin(x3);
119           { CL_TIMING;
120             for (int rep = repetitions; rep > 0; rep--)
121               { r = asin(x3); }
122           }
123           cout << r << endl << endl;
124         }
125
126         cerr << "acos" << endl;
127         { cl_N r = acos(x3);
128           { CL_TIMING;
129             for (int rep = repetitions; rep > 0; rep--)
130               { r = acos(x3); }
131           }
132           cout << r << endl << endl;
133         }
134
135         cerr << "atan" << endl;
136         { cl_F r = atan(x3);
137           { CL_TIMING;
138             for (int rep = repetitions; rep > 0; rep--)
139               { r = atan(x3); }
140           }
141           cout << r << endl << endl;
142         }
143
144         cerr << "sinh" << endl;
145         { cl_F r = sinh(x2);
146           { CL_TIMING;
147             for (int rep = repetitions; rep > 0; rep--)
148               { r = sinh(x2); }
149           }
150           cout << r << endl << endl;
151         }
152
153         cerr << "cosh" << endl;
154         { cl_F r = cosh(x2);
155           { CL_TIMING;
156             for (int rep = repetitions; rep > 0; rep--)
157               { r = cosh(x2); }
158           }
159           cout << r << endl << endl;
160         }
161
162         cerr << "asinh" << endl;
163         { cl_N r = asinh(x3);
164           { CL_TIMING;
165             for (int rep = repetitions; rep > 0; rep--)
166               { r = asinh(x3); }
167           }
168           cout << r << endl << endl;
169         }
170
171         cerr << "acosh" << endl;
172         { cl_N r = acosh(1+x3);
173           { CL_TIMING;
174             for (int rep = repetitions; rep > 0; rep--)
175               { r = acosh(1+x3); }
176           }
177           cout << r << endl << endl;
178         }
179
180         cerr << "atanh" << endl;
181         { cl_N r = atanh(x3);
182           { CL_TIMING;
183             for (int rep = repetitions; rep > 0; rep--)
184               { r = atanh(x3); }
185           }
186           cout << r << endl << endl;
187         }
188
189 }