]> www.ginac.de Git - cln.git/blob - tests/timeprint-compare.cc
91cb70341d8de77fc407b8be7f757989177426a5
[cln.git] / tests / timeprint-compare.cc
1 #include <cl_number.h>
2 #include <cl_io.h>
3 #include <cl_integer.h>
4 #include <cl_random.h>
5 #include <stdlib.h>
6 #include <string.h>
7 #include <cl_timing.h>
8 #include <cl_print.h>
9 #include <cl_malloc.h>
10 #include <cl_abort.h>
11
12 int main (int argc, char * argv[])
13 {
14         int repetitions = 1;
15         if ((argc >= 3) && !strcmp(argv[1],"-r")) {
16                 repetitions = atoi(argv[2]);
17                 argc -= 2; argv += 2;
18         }
19         if (argc < 2)
20                 exit(1);
21         cl_I m = cl_I(argv[1]);
22         cl_I M = (cl_I)1 << (intDsize*m);
23         cl_I a = random_I(M);
24         extern int cl_digits_algo;
25         // One run to fill the cache.
26         {
27                 char* p = (cl_digits_algo = 0, cl_decimal_string(a));
28                 char* q = (cl_digits_algo = 1, cl_decimal_string(a));
29                 if (strcmp(p,q)) cl_abort();
30                 cl_free_hook(p);
31                 cl_free_hook(q);
32         }
33         // Now start the timing.
34         cl_digits_algo = 0;
35         { CL_TIMING;
36           for (int rep = repetitions; rep > 0; rep--)
37             { char* p = cl_decimal_string(a); cl_free_hook(p); }
38         }
39         cl_digits_algo = 1;
40         { CL_TIMING;
41           for (int rep = repetitions; rep > 0; rep--)
42             { char* p = cl_decimal_string(a); cl_free_hook(p); }
43         }
44 }