@@ -1158,7 +1158,7 @@ static int test_mp_read_radix(void)
11581158 size_t written , maxlen ;
11591159 int bignum , i ;
11601160
1161- char * buffer , * bcpy ;
1161+ char * buffer , * bcpy , * startb ;
11621162
11631163 clock_t start , stop , t_slow , t_fast ;
11641164
@@ -1191,18 +1191,19 @@ static int test_mp_read_radix(void)
11911191
11921192 /* Test the fast method with a slightly larger number */
11931193
1194- /* Must be bigger than the cut-off value, of course */
1195- bignum = ( 2 * 20 * MP_RADIX_BARRETT_START_MULTIPLICATOR ) * 10 ;
1194+ /* Needs to be big enough to make a sufficiently large timing difference */
1195+ bignum = 30000 ;
11961196 buffer = (char * )malloc ((size_t )(bignum + 2 ));
11971197 if (buffer == NULL ) {
11981198 goto LBL_ERR ;
11991199 }
12001200 DO (mp_rand (& a , bignum / MP_DIGIT_BIT ));
1201- printf ( "\nNumber of limbs in &b = %d, bit_count of &b = %d\n" , bignum / MP_DIGIT_BIT , mp_count_bits (& a ));
1201+ fprintf ( stderr , "\nNumber of limbs in &b = %d, bit_count of &b = %d\n" , bignum / MP_DIGIT_BIT , mp_count_bits (& a ));
12021202 start = clock ();
12031203 for (i = 2 ; i < 65 ; i ++ ) {
12041204 /* printf("FAST radix = %d\n",i); */
12051205 DO (mp_to_radix (& a , buffer , (size_t )(bignum + 1 ), & written , i ));
1206+ mp_zero (& b );
12061207 DO (mp_read_radix (& b , buffer , i ));
12071208 EXPECT (mp_cmp (& a , & b ) == MP_EQ );
12081209 }
@@ -1215,7 +1216,11 @@ static int test_mp_read_radix(void)
12151216 /* printf("SLOW radix = %d\n",i); */
12161217 maxlen = (size_t )(bignum + 1 );
12171218 bcpy = buffer ;
1219+ /* s_mp_slower_to_radix is very rudimentary as a stand-alone */
1220+ startb = bcpy ;
12181221 DO (s_mp_slower_to_radix (& a , & bcpy , & maxlen , & written , i , false));
1222+ bcpy = startb ;
1223+ mp_zero (& b );
12191224 DO (s_mp_slower_read_radix (& b , bcpy , 0 , strlen (bcpy ), i ));
12201225 EXPECT (mp_cmp (& a , & b ) == MP_EQ );
12211226 }
@@ -1226,15 +1231,14 @@ static int test_mp_read_radix(void)
12261231 fprintf (stderr ,"SLOW: %.10f, FAST: %.10f\n" , (double )t_slow /(double )CLOCKS_PER_SEC ,
12271232 (double )t_fast /(double )CLOCKS_PER_SEC );
12281233
1229- /* Check if the branching works.
1234+ /* Check if the branching works. */
12301235 if (MP_HAS (S_MP_FASTER_READ_RADIX ) && MP_HAS (S_MP_FASTER_TO_RADIX )) {
12311236 if (t_fast > t_slow ) {
12321237 fprintf (stderr , "Timing suspicious in test_mp_read_radix. No fast multiplication? Cut-off too low?\n" );
12331238 DO (mp_fwrite (& a , 16 , stderr ));
12341239 goto LBL_ERR ;
12351240 }
12361241 }
1237- */
12381242
12391243 free (buffer );
12401244
0 commit comments