source: git/ntl/src/PolyTimeTest.c @ 287cc8

spielwiese
Last change on this file since 287cc8 was 287cc8, checked in by Hans Schönemann <hannes@…>, 14 years ago
ntl 5.5.2 git-svn-id: file:///usr/local/Singular/svn/trunk@12402 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 2.3 KB
Line 
1
2#include <NTL/ZZ_pX.h>
3
4#include <stdio.h>
5
6NTL_CLIENT
7
8
9double clean_data(double *t)
10{
11   double x, y, z;
12   long i, ix, iy, n;
13
14   x = t[0]; ix = 0;
15   y = t[0]; iy = 0;
16
17   for (i = 1; i < 5; i++) {
18      if (t[i] < x) {
19         x = t[i];
20         ix = i;
21      }
22      if (t[i] > y) {
23         y = t[i];
24         iy = i;
25      }
26   }
27
28   z = 0; n = 0;
29   for (i = 0; i < 5; i++) {
30      if (i != ix && i != iy) z+= t[i], n++;
31   }
32
33   z = z/n;
34
35   return z;
36}
37
38void print_flag()
39{
40
41
42#ifdef NTL_TBL_REM
43printf("TBL_REM ");
44#else
45printf("DEFAULT ");
46#endif
47
48
49printf("\n");
50
51}
52
53
54int main()
55{
56   _ntl_gmp_hack = 0;
57
58
59   long n, k;
60
61   n = 200;
62   k = 10*NTL_ZZ_NBITS;
63
64   ZZ p;
65
66   RandomLen(p, k);
67
68
69   ZZ_p::init(p);         // initialization
70
71   ZZ_pX f, g, h, r1, r2, r3;
72
73   random(g, n);    // g = random polynomial of degree < n
74   random(h, n);    // h =             "   "
75   random(f, n);    // f =             "   "
76
77   SetCoeff(f, n);  // Sets coefficient of X^n to 1
78
79   // For doing arithmetic mod f quickly, one must pre-compute
80   // some information.
81
82   ZZ_pXModulus F;
83   build(F, f);
84
85   PlainMul(r1, g, h);  // this uses classical arithmetic
86   PlainRem(r1, r1, f);
87
88   MulMod(r2, g, h, F);  // this uses the FFT
89
90   MulMod(r3, g, h, f);  // uses FFT, but slower
91
92   // compare the results...
93
94   if (r1 != r2) {
95      printf("999999999999999 ");
96      print_flag();
97      return 0;
98   }
99   else if (r1 != r3) {
100      printf("999999999999999 ");
101      print_flag();
102      return 0;
103   }
104
105   double t;
106   long i;
107   long iter;
108
109   n = 1024;
110   k = 1024;
111   RandomLen(p, k);
112
113   ZZ_p::init(p);
114
115   ZZ_pX j1, j2, j3;
116
117   random(j1, n);
118   random(j2, n);
119
120   mul(j3, j1, j2);
121
122   iter = 1;
123
124   do {
125     t = GetTime();
126     for (i = 0; i < iter; i++) {
127        FFTMul(j3, j1, j2);
128     }
129     t = GetTime() - t;
130     iter = 2*iter;
131   } while(t < 1);
132
133   iter = iter/2;
134
135   iter = long((2/t)*iter) + 1;
136
137   double tvec[5];
138   long w;
139
140   for (w = 0; w < 5; w++) {
141     t = GetTime();
142     for (i = 0; i < iter; i++) {
143        FFTMul(j3, j1, j2);
144     }
145     t = GetTime() - t;
146     tvec[w] = t;
147   }
148
149
150   t = clean_data(tvec);
151
152   t = floor((t/iter)*1e12);
153
154   if (t < 0 || t >= 1e15)
155      printf("999999999999999 ");
156   else
157      printf("%015.0f ", t);
158
159   printf(" [%ld] ", iter);
160
161   print_flag();
162
163   return 0;
164}
Note: See TracBrowser for help on using the repository browser.