]> www.ginac.de Git - cln.git/blob - tests/timepi.cc
f2bdcbeb4dfbda07718b703571ea8bda05ca8501
[cln.git] / tests / timepi.cc
1 #include <cl_number.h>
2 #include <cl_io.h>
3 #include <cl_float.h>
4 #include <cl_float_io.h>
5 #include <cl_real.h>
6 #include <cl_random.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <cl_timing.h>
10
11 int main (int argc, char * argv[])
12 {
13         int repetitions = 1;
14         if ((argc >= 3) && !strcmp(argv[1],"-r")) {
15                 repetitions = atoi(argv[2]);
16                 argc -= 2; argv += 2;
17         }
18         if (argc < 2)
19                 exit(1);
20 #if 0
21         uintL len = atoi(argv[1]);
22         extern cl_LF compute_pi_brent_salamin (uintC len);
23         extern cl_LF compute_pi_brent_salamin_quartic (uintC len);
24         extern cl_LF compute_pi_ramanujan_163 (uintC len);
25         extern cl_LF compute_pi_ramanujan_163_fast (uintC len);
26         cl_LF p;
27         { CL_TIMING;
28           for (int rep = repetitions; rep > 0; rep--)
29             { p = compute_pi_brent_salamin(len); }
30         }
31 //      cout << p << endl;
32         { CL_TIMING;
33           for (int rep = repetitions; rep > 0; rep--)
34             { p = compute_pi_brent_salamin_quartic(len); }
35         }
36 //      cout << p << endl;
37         { CL_TIMING;
38           for (int rep = repetitions; rep > 0; rep--)
39             { p = compute_pi_ramanujan_163(len); }
40         }
41 //      cout << p << endl;
42         { CL_TIMING;
43           for (int rep = repetitions; rep > 0; rep--)
44             { p = compute_pi_ramanujan_163_fast(len); }
45         }
46 //      cout << p << endl;
47 #else
48         // Here the argument is N *decimal* digits, not N*32 bits!
49         int n = atoi(argv[1]);
50         cl_float_format_t prec = cl_float_format(n);
51         cl_F p;
52         fprint(cl_stderr, "Computing pi\n");
53         { CL_TIMING; p = cl_pi(prec); }
54         fprint(cl_stderr, "Converting pi to decimal\n");
55         { CL_TIMING; cout << p << endl << endl; }
56 #endif
57 }