]> www.ginac.de Git - cln.git/blob - benchmarks/timebench1.cc
* cln.pc.in: Fix typo.
[cln.git] / benchmarks / timebench1.cc
1 // Benchmarks from the LiDIA home page
2
3 #include <cln/number.h>
4 #include <cln/io.h>
5 #include <cln/integer.h>
6 #include <cln/float.h>
7 #include <cln/float_io.h>
8 #include <cln/real.h>
9 #include <cln/real_io.h>
10 #include <cln/complex.h>
11 #include <cln/complex_io.h>
12 #include <cstdlib>
13 #include <cstring>
14 #include <cln/timing.h>
15
16 // Timings on Linux i486 33 MHz, 1000 decimal places = 104 32-bit words.
17 // Function              LiDIA       Pari       CLISP         CLN
18 //  pi                               0.17 / 0   0.38 / 0      0.12 / 0
19 //  gamma                            7.51 / 0    --           3.75 / 0
20 //  e                                1.20       5.06 / 0.20   0.66 / 0.10
21 //  multiplication                   0.018      0.010         0.010
22 //  sqrt(3)                          0.051      0.012         0.01
23 //  exp(log(2))                      3.13       0.08 / 3.94   0.04
24 //  log(exp(2))                      3.07       4.93 / 2.75   1.34
25 //  sin(pi/3)                        1.53       2.98          0.58
26 //  cos(pi/3)                        1.59       2.16          0.58
27 //  arcsin(sqrt(3)/2)                4.24       2.22          1.26
28 //  arccos(sqrt(3)/2)                4.26       2.22          1.26
29 //  sinh(log(2))                     3.16       2.02          0.03
30 //  cosh(log(2))                     3.17       2.09          0.04
31 //  arsinh(pi)                       1.93       2.62          0.65
32 //  arcosh(pi)                       1.95       2.26          0.69
33 // (Versions: Pari 1.39, clisp-1996-07-22, cln-1996-11-17.)
34
35 // Timings on Solaris Sparc 20, 75 MHz, 1000 decimal places = 104 32-bit words.
36 // Function              LiDIA       Pari       CLISP         CLN
37 //  pi                   0.06 / 0    0.04 / 0                 0.028 / 0
38 //  gamma                1.98 / 0    1.26 / 0                 1.99 / 0
39 //  e                    0           0.15                     0.15
40 //  multiplication
41 //  sqrt(3)              0.0025      0.01                     0.0025
42 //  exp(log(2))          0.25        0.39                     0.010
43 //  log(exp(2))          0.21        0.39                     0.31
44 //  sin(pi/3)            0.071       0.18                     0.13
45 //  cos(pi/3)            0.070       0.19                     0.13
46 //  arcsin(sqrt(3)/2)    0.30        0.55                     0.27
47 //  arccos(sqrt(3)/2)    0.30        0.55                     0.27
48 //  sinh(log(2))         0.25        0.41                     0.010
49 //  cosh(log(2))         0.25        0.40                     0.010
50 //  arsinh(pi)           0.16        0.26                     0.144
51 //  arcosh(pi)           0.16        0.26                     0.153
52 // (Versions: Pari 1.39, LiDIA 1.2.1 with libI, cln-1996-10-13.)
53
54 int main (int argc, char * argv[])
55 {
56         int repetitions = 1;
57         if ((argc >= 3) && !strcmp(argv[1],"-r")) {
58                 repetitions = atoi(argv[2]);
59                 argc -= 2; argv += 2;
60         }
61         if (argc < 1)
62                 exit(1);
63
64         fprint(std::cerr, "Number of repetitions: ");
65         fprintdecimal(std::cerr, repetitions);
66         fprint(std::cerr, "\n");
67
68         float_format_t prec = float_format(1000);
69
70         fprint(std::cerr, "pi\n");
71         { cl_F p;
72           { CL_TIMING; p = pi(prec); }
73           { CL_TIMING;
74             for (int rep = repetitions; rep > 0; rep--)
75               { cl_F p = pi(prec); }
76           }
77           cout << p << endl << endl;
78         }
79
80         fprint(std::cerr, "gamma\n");
81         { cl_F p;
82           { CL_TIMING; p = eulerconst(prec); }
83           { CL_TIMING;
84             for (int rep = repetitions; rep > 0; rep--)
85               { cl_F p = eulerconst(prec); }
86           }
87           cout << p << endl << endl;
88         }
89
90         fprint(std::cerr, "e\n");
91         { cl_F p = exp1(prec);
92           { CL_TIMING;
93             for (int rep = repetitions; rep > 0; rep--)
94               { cl_F p = exp1(prec); }
95           }
96           cout << p << endl << endl;
97         }
98
99         fprint(std::cerr, "sqrt(3)\n");
100         { cl_R p = sqrt(cl_float(3,prec));
101           { CL_TIMING;
102             for (int rep = repetitions; rep > 0; rep--)
103               { cl_R p = sqrt(cl_float(3,prec)); }
104           }
105           cout << p << endl << endl;
106         }
107
108         fprint(std::cerr, "exp(log(2))\n");
109         { cl_N p = exp(log(cl_float(2,prec)));
110           { CL_TIMING;
111             for (int rep = repetitions; rep > 0; rep--)
112               { cl_N p = exp(log(cl_float(2,prec))); }
113           }
114           cout << p << endl << endl;
115         }
116
117         fprint(std::cerr, "log(exp(2))\n");
118         { cl_N p = log(exp(cl_float(2,prec)));
119           { CL_TIMING;
120             for (int rep = repetitions; rep > 0; rep--)
121               { cl_N p = log(exp(cl_float(2,prec))); }
122           }
123           cout << p << endl << endl;
124         }
125
126         fprint(std::cerr, "sin(pi/3)\n");
127         { cl_R p = sin(pi(prec)/3);
128           { CL_TIMING;
129             for (int rep = repetitions; rep > 0; rep--)
130               { cl_R p = sin(pi(prec)/3); }
131           }
132           cout << p << endl << endl;
133         }
134
135         fprint(std::cerr, "cos(pi/3)\n");
136         { cl_R p = cos(pi(prec)/3);
137           { CL_TIMING;
138             for (int rep = repetitions; rep > 0; rep--)
139               { cl_R p = cos(pi(prec)/3); }
140           }
141           cout << p << endl << endl;
142         }
143
144         fprint(std::cerr, "arcsin(sqrt(3)/2)\n");
145         { cl_N p = asin(sqrt(cl_float(3,prec))/2);
146           { CL_TIMING;
147             for (int rep = repetitions; rep > 0; rep--)
148               { cl_N p = asin(sqrt(cl_float(3,prec))/2); }
149           }
150           cout << p << endl << endl;
151         }
152
153         fprint(std::cerr, "arccos(sqrt(3)/2)\n");
154         { cl_N p = acos(sqrt(cl_float(3,prec))/2);
155           { CL_TIMING;
156             for (int rep = repetitions; rep > 0; rep--)
157               { cl_N p = acos(sqrt(cl_float(3,prec))/2); }
158           }
159           cout << p << endl << endl;
160         }
161
162         fprint(std::cerr, "sinh(log(2))\n");
163         { cl_N p = sinh(log(cl_float(2,prec)));
164           { CL_TIMING;
165             for (int rep = repetitions; rep > 0; rep--)
166               { cl_N p = sinh(log(cl_float(2,prec))); }
167           }
168           cout << p << endl << endl;
169         }
170
171         fprint(std::cerr, "cosh(log(2))\n");
172         { cl_N p = cosh(log(cl_float(2,prec)));
173           { CL_TIMING;
174             for (int rep = repetitions; rep > 0; rep--)
175               { cl_N p = cosh(log(cl_float(2,prec))); }
176           }
177           cout << p << endl << endl;
178         }
179
180         fprint(std::cerr, "arsinh(pi)\n");
181         { cl_N p = asinh(pi(prec));
182           { CL_TIMING;
183             for (int rep = repetitions; rep > 0; rep--)
184               { cl_N p = asinh(pi(prec)); }
185           }
186           cout << p << endl << endl;
187         }
188
189         fprint(std::cerr, "arcosh(pi)\n");
190         { cl_N p = acosh(pi(prec));
191           { CL_TIMING;
192             for (int rep = repetitions; rep > 0; rep--)
193               { cl_N p = acosh(pi(prec)); }
194           }
195           cout << p << endl << endl;
196         }
197
198 }