]> www.ginac.de Git - cln.git/blob - tests/timediv2adic-compare.cc
* Last bits for release 1.1.5.
[cln.git] / tests / timediv2adic-compare.cc
1 #include <cln/number.h>
2 #include <cln/io.h>
3 #include <cln/integer.h>
4 #include "cl_DS.h"
5 #include "cl_2DS.h"
6 #include <cln/random.h>
7 #include "cl_random_impl.h"
8 #include <cln/abort.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include <cln/timing.h>
12 using namespace cln;
13
14 int main (int argc, char * argv[])
15 {
16         int repetitions = 1;
17         if ((argc >= 3) && !strcmp(argv[1],"-r")) {
18                 repetitions = atoi(argv[2]);
19                 argc -= 2; argv += 2;
20         }
21         if (argc < 3)
22                 exit(1);
23         uintL a_len = atoi(argv[1]);
24         uintL b_len = atoi(argv[2]);
25         if (!(a_len >= b_len && b_len > 0))
26                 exit(1);
27         SAVE_NUM_STACK;
28         uintD* a_MSDptr;
29         uintD* a_LSDptr;
30         uintD* b_MSDptr;
31         uintD* b_LSDptr;
32         uintD* q_MSDptr;
33         uintD* q_LSDptr;
34         uintD* q1_MSDptr;
35         uintD* q1_LSDptr;
36         num_stack_alloc(a_len,a_MSDptr=,a_LSDptr=);
37         num_stack_alloc(b_len,b_MSDptr=,b_LSDptr=);
38         num_stack_alloc(a_len,q_MSDptr=,q_LSDptr=);
39         num_stack_alloc(a_len,q1_MSDptr=,q1_LSDptr=);
40         random_UDS(default_random_state,a_MSDptr,a_len);
41         random_UDS(default_random_state,b_MSDptr,b_len);
42         lspref(b_LSDptr,0) |= 1; // force b to be odd
43         extern int div2adic_algo;
44         // Check.
45         div2adic_algo = 0;
46         div2adic(a_len,a_LSDptr,b_len,b_LSDptr,q_LSDptr);
47         div2adic_algo = 1;
48         div2adic(a_len,a_LSDptr,b_len,b_LSDptr,q1_LSDptr);
49         if (compare_loop_msp(q_MSDptr,q1_MSDptr,a_len)) cl_abort();
50         // Time.
51         div2adic_algo = 0;
52         { CL_TIMING;
53           for (int rep = repetitions; rep > 0; rep--)
54             { div2adic(a_len,a_LSDptr,b_len,b_LSDptr,q_LSDptr); }
55         }
56         div2adic_algo = 1;
57         { CL_TIMING;
58           for (int rep = repetitions; rep > 0; rep--)
59             { div2adic(a_len,a_LSDptr,b_len,b_LSDptr,q_LSDptr); }
60         }
61 }