]> www.ginac.de Git - cln.git/blob - benchmarks/timebench1.LiDIA.cc
* cln.pc.in: Fix typo.
[cln.git] / benchmarks / timebench1.LiDIA.cc
1 #include <LiDIA/bigfloat.h>
2 #include <LiDIA/timer.h>
3
4 int main (int argc, char * argv[])
5 {
6         int repetitions = 1;
7         if ((argc >= 3) && !strcmp(argv[1],"-r")) {
8                 repetitions = atoi(argv[2]);
9                 argc -= 2; argv += 2;
10         }
11         if (argc < 1)
12                 exit(1);
13
14         bigfloat::precision(1000);
15
16         cerr << "pi\n";
17         { bigfloat p;
18           { timer t; t.set_print_mode(0); t.start_timer();
19             p = Pi();
20             t.stop_timer(); cerr << t << endl;
21           }
22           { timer t; t.set_print_mode(0); t.start_timer();
23             for (int rep = repetitions; rep > 0; rep--)
24               { bigfloat p = Pi(); }
25             t.stop_timer(); cerr << t << endl;
26           }
27           cout << p << endl << endl;
28         }
29
30         cerr << "gamma\n";
31         { bigfloat p;
32           { timer t; t.set_print_mode(0); t.start_timer();
33             p = Euler();
34             t.stop_timer(); cerr << t << endl;
35           }
36           { timer t; t.set_print_mode(0); t.start_timer();
37             for (int rep = repetitions; rep > 0; rep--)
38               { bigfloat p = Euler(); }
39             t.stop_timer(); cerr << t << endl;
40           }
41           cout << p << endl << endl;
42         }
43
44         cerr << "e\n";
45         { bigfloat p = E();
46           { timer t; t.set_print_mode(0); t.start_timer();
47             for (int rep = repetitions; rep > 0; rep--)
48               { bigfloat p = E(); }
49             t.stop_timer(); cerr << t << endl;
50           }
51           cout << p << endl << endl;
52         }
53
54         cerr << "sqrt(3)\n";
55         { bigfloat p = sqrt((bigfloat)3);
56           { timer t; t.set_print_mode(0); t.start_timer();
57             for (int rep = repetitions; rep > 0; rep--)
58               { bigfloat p = sqrt((bigfloat)3); }
59             t.stop_timer(); cerr << t << endl;
60           }
61           cout << p << endl << endl;
62         }
63
64         cerr << "exp(log(2))\n";
65         { bigfloat p = exp(log((bigfloat)2));
66           { timer t; t.set_print_mode(0); t.start_timer();
67             for (int rep = repetitions; rep > 0; rep--)
68               { bigfloat p = exp(log((bigfloat)2)); }
69             t.stop_timer(); cerr << t << endl;
70           }
71           cout << p << endl << endl;
72         }
73
74         cerr << "log(exp(2))\n";
75         { bigfloat p = log(exp((bigfloat)2));
76           { timer t; t.set_print_mode(0); t.start_timer();
77             for (int rep = repetitions; rep > 0; rep--)
78               { bigfloat p = log(exp((bigfloat)2)); }
79             t.stop_timer(); cerr << t << endl;
80           }
81           cout << p << endl << endl;
82         }
83
84         cerr << "sin(pi/3)\n";
85         { bigfloat p = sin(Pi()/3);
86           { timer t; t.set_print_mode(0); t.start_timer();
87             for (int rep = repetitions; rep > 0; rep--)
88               { bigfloat p = sin(Pi()/3); }
89             t.stop_timer(); cerr << t << endl;
90           }
91           cout << p << endl << endl;
92         }
93
94         cerr << "cos(pi/3)\n";
95         { bigfloat p = cos(Pi()/3);
96           { timer t; t.set_print_mode(0); t.start_timer();
97             for (int rep = repetitions; rep > 0; rep--)
98               { bigfloat p = cos(Pi()/3); }
99             t.stop_timer(); cerr << t << endl;
100           }
101           cout << p << endl << endl;
102         }
103
104         cerr << "arcsin(sqrt(3)/2)\n";
105         { bigfloat p = asin(sqrt((bigfloat)3)/2);
106           { timer t; t.set_print_mode(0); t.start_timer();
107             for (int rep = repetitions; rep > 0; rep--)
108               { bigfloat p = asin(sqrt((bigfloat)3)/2); }
109             t.stop_timer(); cerr << t << endl;
110           }
111           cout << p << endl << endl;
112         }
113
114         cerr << "arccos(sqrt(3)/2)\n";
115         { bigfloat p = acos(sqrt((bigfloat)3)/2);
116           { timer t; t.set_print_mode(0); t.start_timer();
117             for (int rep = repetitions; rep > 0; rep--)
118               { bigfloat p = acos(sqrt((bigfloat)3)/2); }
119             t.stop_timer(); cerr << t << endl;
120           }
121           cout << p << endl << endl;
122         }
123
124         cerr << "sinh(log(2))\n";
125         { bigfloat p = sinh(log((bigfloat)2));
126           { timer t; t.set_print_mode(0); t.start_timer();
127             for (int rep = repetitions; rep > 0; rep--)
128               { bigfloat p = sinh(log((bigfloat)2)); }
129             t.stop_timer(); cerr << t << endl;
130           }
131           cout << p << endl << endl;
132         }
133
134         cerr << "cosh(log(2))\n";
135         { bigfloat p = cosh(log((bigfloat)2));
136           { timer t; t.set_print_mode(0); t.start_timer();
137             for (int rep = repetitions; rep > 0; rep--)
138               { bigfloat p = cosh(log((bigfloat)2)); }
139             t.stop_timer(); cerr << t << endl;
140           }
141           cout << p << endl << endl;
142         }
143
144         cerr << "arsinh(pi)\n";
145         { bigfloat p = asinh(Pi());
146           { timer t; t.set_print_mode(0); t.start_timer();
147             for (int rep = repetitions; rep > 0; rep--)
148               { bigfloat p = asinh(Pi()); }
149             t.stop_timer(); cerr << t << endl;
150           }
151           cout << p << endl << endl;
152         }
153
154         cerr << "arcosh(pi)\n";
155         { bigfloat p = acosh(Pi());
156           { timer t; t.set_print_mode(0); t.start_timer();
157             for (int rep = repetitions; rep > 0; rep--)
158               { bigfloat p = acosh(Pi()); }
159             t.stop_timer(); cerr << t << endl;
160           }
161           cout << p << endl << endl;
162         }
163
164 }
165
166
167