1 // Benchmarks from the LiDIA home page
3 #include <cln/number.h>
5 #include <cln/integer.h>
7 #include <cln/float_io.h>
9 #include <cln/real_io.h>
10 #include <cln/complex.h>
11 #include <cln/complex_io.h>
14 #include <cln/timing.h>
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.)
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
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.)
54 int main (int argc, char * argv[])
57 if ((argc >= 3) && !strcmp(argv[1],"-r")) {
58 repetitions = atoi(argv[2]);
64 fprint(std::cerr, "Number of repetitions: ");
65 fprintdecimal(std::cerr, repetitions);
66 fprint(std::cerr, "\n");
68 float_format_t prec = float_format(1000);
70 fprint(std::cerr, "pi\n");
72 { CL_TIMING; p = pi(prec); }
74 for (int rep = repetitions; rep > 0; rep--)
75 { cl_F p = pi(prec); }
77 cout << p << endl << endl;
80 fprint(std::cerr, "gamma\n");
82 { CL_TIMING; p = eulerconst(prec); }
84 for (int rep = repetitions; rep > 0; rep--)
85 { cl_F p = eulerconst(prec); }
87 cout << p << endl << endl;
90 fprint(std::cerr, "e\n");
91 { cl_F p = exp1(prec);
93 for (int rep = repetitions; rep > 0; rep--)
94 { cl_F p = exp1(prec); }
96 cout << p << endl << endl;
99 fprint(std::cerr, "sqrt(3)\n");
100 { cl_R p = sqrt(cl_float(3,prec));
102 for (int rep = repetitions; rep > 0; rep--)
103 { cl_R p = sqrt(cl_float(3,prec)); }
105 cout << p << endl << endl;
108 fprint(std::cerr, "exp(log(2))\n");
109 { cl_N p = exp(log(cl_float(2,prec)));
111 for (int rep = repetitions; rep > 0; rep--)
112 { cl_N p = exp(log(cl_float(2,prec))); }
114 cout << p << endl << endl;
117 fprint(std::cerr, "log(exp(2))\n");
118 { cl_N p = log(exp(cl_float(2,prec)));
120 for (int rep = repetitions; rep > 0; rep--)
121 { cl_N p = log(exp(cl_float(2,prec))); }
123 cout << p << endl << endl;
126 fprint(std::cerr, "sin(pi/3)\n");
127 { cl_R p = sin(pi(prec)/3);
129 for (int rep = repetitions; rep > 0; rep--)
130 { cl_R p = sin(pi(prec)/3); }
132 cout << p << endl << endl;
135 fprint(std::cerr, "cos(pi/3)\n");
136 { cl_R p = cos(pi(prec)/3);
138 for (int rep = repetitions; rep > 0; rep--)
139 { cl_R p = cos(pi(prec)/3); }
141 cout << p << endl << endl;
144 fprint(std::cerr, "arcsin(sqrt(3)/2)\n");
145 { cl_N p = asin(sqrt(cl_float(3,prec))/2);
147 for (int rep = repetitions; rep > 0; rep--)
148 { cl_N p = asin(sqrt(cl_float(3,prec))/2); }
150 cout << p << endl << endl;
153 fprint(std::cerr, "arccos(sqrt(3)/2)\n");
154 { cl_N p = acos(sqrt(cl_float(3,prec))/2);
156 for (int rep = repetitions; rep > 0; rep--)
157 { cl_N p = acos(sqrt(cl_float(3,prec))/2); }
159 cout << p << endl << endl;
162 fprint(std::cerr, "sinh(log(2))\n");
163 { cl_N p = sinh(log(cl_float(2,prec)));
165 for (int rep = repetitions; rep > 0; rep--)
166 { cl_N p = sinh(log(cl_float(2,prec))); }
168 cout << p << endl << endl;
171 fprint(std::cerr, "cosh(log(2))\n");
172 { cl_N p = cosh(log(cl_float(2,prec)));
174 for (int rep = repetitions; rep > 0; rep--)
175 { cl_N p = cosh(log(cl_float(2,prec))); }
177 cout << p << endl << endl;
180 fprint(std::cerr, "arsinh(pi)\n");
181 { cl_N p = asinh(pi(prec));
183 for (int rep = repetitions; rep > 0; rep--)
184 { cl_N p = asinh(pi(prec)); }
186 cout << p << endl << endl;
189 fprint(std::cerr, "arcosh(pi)\n");
190 { cl_N p = acosh(pi(prec));
192 for (int rep = repetitions; rep > 0; rep--)
193 { cl_N p = acosh(pi(prec)); }
195 cout << p << endl << endl;