source: git/ntl/src/MulTimeTest.c @ 33a041

spielwiese
Last change on this file since 33a041 was 2cfffe, checked in by Hans Schönemann <hannes@…>, 21 years ago
This commit was generated by cvs2svn to compensate for changes in r6316, which included commits to RCS files with non-trunk default branches. git-svn-id: file:///usr/local/Singular/svn/trunk@6317 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 1.9 KB
Line 
1
2#include <NTL/ZZ_pX.h>
3
4#include <stdio.h>
5
6NTL_CLIENT
7
8void print_flag()
9{
10
11#if defined(NTL_LONG_LONG)
12printf("LONG_LONG\n");
13#elif defined(NTL_AVOID_FLOAT)
14printf("AVOID_FLOAT\n");
15#else
16printf("DEFAULT\n");
17#endif
18
19}
20
21
22int main()
23{
24   _ntl_gmp_hack = 0;
25
26#ifdef NTL_LONG_LONG
27
28#ifndef NTL_LONG_LONG_TYPE
29#define NTL_LONG_LONG_TYPE long long
30#endif
31
32   if (sizeof(NTL_LONG_LONG_TYPE) != 2*sizeof(long)) {
33      printf("999999999999999 ");
34      print_flag();
35      return 0;
36   }
37
38#endif
39
40   long n, k;
41
42   n = 200;
43   k = 10*NTL_ZZ_NBITS;
44
45   ZZ p;
46
47   GenPrime(p, k);
48
49
50   ZZ_p::init(p);         // initialization
51
52   ZZ_pX f, g, h, r1, r2, r3;
53
54   random(g, n);    // g = random polynomial of degree < n
55   random(h, n);    // h =             "   "
56   random(f, n);    // f =             "   "
57
58   // SetCoeff(f, n);  // Sets coefficient of X^n to 1
59   
60   ZZ_p lc;
61
62   do {
63      random(lc);
64   } while (IsZero(lc));
65
66   SetCoeff(f, n, lc);
67
68   // For doing arithmetic mod f quickly, one must pre-compute
69   // some information.
70
71   ZZ_pXModulus F;
72   build(F, f);
73
74   PlainMul(r1, g, h);  // this uses classical arithmetic
75   PlainRem(r1, r1, f);
76
77   MulMod(r2, g, h, F);  // this uses the FFT
78
79   MulMod(r3, g, h, f);  // uses FFT, but slower
80
81   // compare the results...
82
83   if (r1 != r2) {
84      printf("999999999999999 ");
85      print_flag();
86      return 0;
87   }
88   else if (r1 != r3) {
89      printf("999999999999999 ");
90      print_flag();
91      return 0;
92   }
93
94   ZZ x1, x2, x3, x4;
95   double t;
96   long i;
97
98   RandomLen(x1, 512);
99   RandomBnd(x2, x1);
100   RandomBnd(x3, x1);
101
102   long iter;
103
104   mul(x4, x2, x3);
105
106   iter = 1;
107
108   do {
109     t = GetTime();
110     for (i = 0; i < iter; i++)
111        mul(x4, x2, x3);
112     t = GetTime() - t;
113     iter = 2*iter;
114   } while(t < 1);
115
116   iter = iter/2;
117
118   t = floor((t/iter)*1e14);
119
120   if (t < 0 || t >= 1e15)
121      printf("999999999999999 ");
122   else
123      printf("%015.0f ", t);
124
125   print_flag();
126
127   return 0;
128}
Note: See TracBrowser for help on using the repository browser.