1 /*
2 Copyright 2014 Abhinav Baid
3
4 This file is part of FLINT.
5
6 FLINT is free software: you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License (LGPL) as published
8 by the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version. See <http://www.gnu.org/licenses/>.
10 */
11
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include "profiler.h"
15 #include "flint.h"
16 #include "ulong_extras.h"
17
18 #define ITERS 1000
19
20 typedef struct
21 {
22 ulong * rnums1;
23 ulong * rnums2;
24 flint_bitcnt_t bits1;
25 flint_bitcnt_t bits2;
26 } gcd_t;
27
sample(void * arg,ulong count)28 void sample(void * arg, ulong count)
29 {
30 gcd_t * params = (gcd_t *) arg;
31 ulong i, j;
32
33 for (i = 0; i < count; i++)
34 {
35 prof_start();
36 for (j = 0; j < ITERS; j++)
37 {
38 n_gcd(params->rnums2[j & 1023], params->rnums1[j & 1023]);
39 }
40 prof_stop();
41 }
42 }
43
fill_array(ulong * ret,flint_bitcnt_t bits,flint_rand_t state)44 void fill_array(ulong * ret, flint_bitcnt_t bits, flint_rand_t state)
45 {
46 ulong n;
47 ulong i;
48
49 for (i = 0; i < 1024; i++)
50 {
51 n = n_randbits(state, bits);
52 ret[i] = n;
53 }
54 }
55
main(void)56 int main(void)
57 {
58 double min, max;
59 gcd_t params;
60 FLINT_TEST_INIT(state);
61 int i;
62
63
64 params.rnums1 = flint_malloc(1024*sizeof(ulong));
65 params.rnums2 = flint_malloc(1024*sizeof(ulong));
66
67 flint_printf("n_gcd:\n");
68
69 for (i = 1; i <= 64; i++)
70 {
71 fill_array(params.rnums1, i, state);
72 params.bits1 = i;
73 fill_array(params.rnums2, i, state);
74 prof_repeat(&min, &max, sample, ¶ms);
75 flint_printf("bits1 = %d, bits2 = %d, time is %.3f us\n",
76 i, i, max/(double)ITERS);
77 }
78
79 flint_randclear(state);
80 flint_free(params.rnums1);
81 flint_free(params.rnums2);
82 return 0;
83 }
84