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>
19 // Timings on Linux i486 33 MHz, 1000 decimal places = 104 32-bit words.
20 // Function LiDIA Pari CLISP CLN
21 // pi 0.17 / 0 0.38 / 0 0.12 / 0
22 // gamma 7.51 / 0 -- 3.75 / 0
23 // e 1.20 5.06 / 0.20 0.66 / 0.10
24 // multiplication 0.018 0.010 0.010
25 // sqrt(3) 0.051 0.012 0.01
26 // exp(log(2)) 3.13 0.08 / 3.94 0.04
27 // log(exp(2)) 3.07 4.93 / 2.75 1.34
28 // sin(pi/3) 1.53 2.98 0.58
29 // cos(pi/3) 1.59 2.16 0.58
30 // arcsin(sqrt(3)/2) 4.24 2.22 1.26
31 // arccos(sqrt(3)/2) 4.26 2.22 1.26
32 // sinh(log(2)) 3.16 2.02 0.03
33 // cosh(log(2)) 3.17 2.09 0.04
34 // arsinh(pi) 1.93 2.62 0.65
35 // arcosh(pi) 1.95 2.26 0.69
36 // (Versions: Pari 1.39, clisp-1996-07-22, cln-1996-11-17.)
38 // Timings on Solaris Sparc 20, 75 MHz, 1000 decimal places = 104 32-bit words.
39 // Function LiDIA Pari CLISP CLN
40 // pi 0.06 / 0 0.04 / 0 0.028 / 0
41 // gamma 1.98 / 0 1.26 / 0 1.99 / 0
44 // sqrt(3) 0.0025 0.01 0.0025
45 // exp(log(2)) 0.25 0.39 0.010
46 // log(exp(2)) 0.21 0.39 0.31
47 // sin(pi/3) 0.071 0.18 0.13
48 // cos(pi/3) 0.070 0.19 0.13
49 // arcsin(sqrt(3)/2) 0.30 0.55 0.27
50 // arccos(sqrt(3)/2) 0.30 0.55 0.27
51 // sinh(log(2)) 0.25 0.41 0.010
52 // cosh(log(2)) 0.25 0.40 0.010
53 // arsinh(pi) 0.16 0.26 0.144
54 // arcosh(pi) 0.16 0.26 0.153
55 // (Versions: Pari 1.39, LiDIA 1.2.1 with libI, cln-1996-10-13.)
57 int main (int argc, char * argv[])
60 if ((argc >= 3) && !strcmp(argv[1],"-r")) {
61 repetitions = atoi(argv[2]);
67 fprint(std::cerr, "Number of repetitions: ");
68 fprintdecimal(std::cerr, repetitions);
69 fprint(std::cerr, "\n");
71 float_format_t prec = float_format(1000);
73 fprint(std::cerr, "pi\n");
75 { CL_TIMING; p = pi(prec); }
77 for (int rep = repetitions; rep > 0; rep--)
78 { cl_F p = pi(prec); }
80 cout << p << endl << endl;
83 fprint(std::cerr, "gamma\n");
85 { CL_TIMING; p = eulerconst(prec); }
87 for (int rep = repetitions; rep > 0; rep--)
88 { cl_F p = eulerconst(prec); }
90 cout << p << endl << endl;
93 fprint(std::cerr, "e\n");
94 { cl_F p = exp1(prec);
96 for (int rep = repetitions; rep > 0; rep--)
97 { cl_F p = exp1(prec); }
99 cout << p << endl << endl;
102 fprint(std::cerr, "sqrt(3)\n");
103 { cl_R p = sqrt(cl_float(3,prec));
105 for (int rep = repetitions; rep > 0; rep--)
106 { cl_R p = sqrt(cl_float(3,prec)); }
108 cout << p << endl << endl;
111 fprint(std::cerr, "exp(log(2))\n");
112 { cl_N p = exp(log(cl_float(2,prec)));
114 for (int rep = repetitions; rep > 0; rep--)
115 { cl_N p = exp(log(cl_float(2,prec))); }
117 cout << p << endl << endl;
120 fprint(std::cerr, "log(exp(2))\n");
121 { cl_N p = log(exp(cl_float(2,prec)));
123 for (int rep = repetitions; rep > 0; rep--)
124 { cl_N p = log(exp(cl_float(2,prec))); }
126 cout << p << endl << endl;
129 fprint(std::cerr, "sin(pi/3)\n");
130 { cl_R p = sin(pi(prec)/3);
132 for (int rep = repetitions; rep > 0; rep--)
133 { cl_R p = sin(pi(prec)/3); }
135 cout << p << endl << endl;
138 fprint(std::cerr, "cos(pi/3)\n");
139 { cl_R p = cos(pi(prec)/3);
141 for (int rep = repetitions; rep > 0; rep--)
142 { cl_R p = cos(pi(prec)/3); }
144 cout << p << endl << endl;
147 fprint(std::cerr, "arcsin(sqrt(3)/2)\n");
148 { cl_N p = asin(sqrt(cl_float(3,prec))/2);
150 for (int rep = repetitions; rep > 0; rep--)
151 { cl_N p = asin(sqrt(cl_float(3,prec))/2); }
153 cout << p << endl << endl;
156 fprint(std::cerr, "arccos(sqrt(3)/2)\n");
157 { cl_N p = acos(sqrt(cl_float(3,prec))/2);
159 for (int rep = repetitions; rep > 0; rep--)
160 { cl_N p = acos(sqrt(cl_float(3,prec))/2); }
162 cout << p << endl << endl;
165 fprint(std::cerr, "sinh(log(2))\n");
166 { cl_N p = sinh(log(cl_float(2,prec)));
168 for (int rep = repetitions; rep > 0; rep--)
169 { cl_N p = sinh(log(cl_float(2,prec))); }
171 cout << p << endl << endl;
174 fprint(std::cerr, "cosh(log(2))\n");
175 { cl_N p = cosh(log(cl_float(2,prec)));
177 for (int rep = repetitions; rep > 0; rep--)
178 { cl_N p = cosh(log(cl_float(2,prec))); }
180 cout << p << endl << endl;
183 fprint(std::cerr, "arsinh(pi)\n");
184 { cl_N p = asinh(pi(prec));
186 for (int rep = repetitions; rep > 0; rep--)
187 { cl_N p = asinh(pi(prec)); }
189 cout << p << endl << endl;
192 fprint(std::cerr, "arcosh(pi)\n");
193 { cl_N p = acosh(pi(prec));
195 for (int rep = repetitions; rep > 0; rep--)
196 { cl_N p = acosh(pi(prec)); }
198 cout << p << endl << endl;