1 /* compute the crossover for recursive and simple multiplication */
12 /* from number.c ... */
13 extern int mul_base_digits
;
14 /* extern int mul_small_digits; */
17 /* global variables */
19 int test_time
= 30 * CLOCKS_PER_SEC
; /* 30 seconds */
21 /* Other things for number.c. */
27 fprintf (stderr
, "Fatal error: Out of memory for malloc.\n");
31 /* Runtime error will print a message and stop the machine. */
36 rt_error (char *mesg
, ...)
44 rt_error (mesg
, va_alist
)
49 char error_mesg
[255];
52 va_start (args
, mesg
);
56 vsprintf (error_mesg
, mesg
, args
);
59 fprintf (stderr
, "Runtime error: %s\n", error_mesg
);
62 /* A runtime warning tells of some action taken by the processor that
63 may change the program execution but was not enough of a problem
64 to stop the execution. */
69 rt_warn (char *mesg
, ...)
77 rt_warn (mesg
, va_alist
)
82 char error_mesg
[255];
85 va_start (args
, mesg
);
89 vsprintf (error_mesg
, mesg
, args
);
92 fprintf (stderr
, "Runtime warning: %s\n", error_mesg
);
104 timeit ( bc_num a
, bc_num b
, int *n
)
114 for (i
=0; i
<test_n
; i
++)
115 bc_multiply(a
,b
,&c
,0);
117 res
= (int) (clock() - first
);
118 } while (res
< test_time
);
122 int debug
= 0; /* Print debugging messages? */
124 int main (int argc
, char **argv
)
126 bc_num ten
, num
, expo
, big
;
136 float permul1
, permul2
;
140 if (strcmp (argv
[1], "-d") == 0)
148 bc_int2num (&ten
, 10);
151 fprintf (stderr
, "Timings are for %d multiplies\n"
152 "Minimum time is %d seconds\n", test_n
,
153 test_time
/CLOCKS_PER_SEC
);
155 /* Two of the same size */
160 fprintf (stderr
, "Testing numbers of the same length.\n");
164 if (debug
) fprintf (stderr
,"Checking %d...\n", mid
);
166 bc_int2num (&expo
, mid
);
167 bc_raise (ten
, expo
, &num
, 0);
168 bc_sub (num
, _one_
, &num
, 0);
170 mul_base_digits
= 2*mid
+1;
171 t1
= timeit (num
, num
, &n1
);
172 permul1
= (float)t1
/(float)n1
;
174 mul_base_digits
= 2*mid
-1;
175 t2
= timeit (num
, num
, &n2
);
176 permul2
= (float)t2
/(float)n2
;
178 if (permul1
< permul2
)
184 fprintf (stderr
, "n1 = %d :: n2 = %d\n", n1
, n2
);
185 fprintf (stderr
, "p1 = %f :: p2 = %f\n", permul1
, permul2
);
190 fprintf (stderr
, "Base digits crossover at %d digits\n", min
);
191 printf ("#define MUL_BASE_DIGITS %d\n", 2*min
);
195 mul_base_digits
= min
;
197 /* Small one times a big one. */
200 bc_int2num (&expo
, smallsize
);
201 bc_raise (ten
, expo
, &big
, 0);
202 bc_sub (num
, _one_
, &big
, 0);
208 fprintf (stderr
, "Testing numbers of the different length.\n");
212 if (debug
) fprintf (stderr
, "Checking %d...\n", mid
);
214 bc_int2num (&expo
, mid
-smallsize
);
215 bc_raise (ten
, expo
, &num
, 0);
216 bc_sub (num
, _one_
, &num
, 0);
218 mul_small_digits
= mid
+1;
219 t1
= timeit (big
, num
, &n1
);
220 permul1
= (float)t1
/(float)n1
;
222 mul_small_digits
= mid
-1;
223 t2
= timeit (big
, num
, &n2
);
224 permul2
= (float)t2
/(float)n2
;
226 if (permul1
< permul2
)
232 fprintf (stderr
, "n1 = %d :: n2 = %d\n", n1
, n2
);
233 fprintf (stderr
, "p1 = %f :: p2 = %f\n", permul1
, permul2
);
238 fprintf (stderr
, "Non equal digits crossover at %d total digits\n", min
);
239 printf ("#define MUL_SMALL_DIGITS = %d\n", min
);