@@ -1529,27 +1529,6 @@ static int test_mp_decr(void)
15291529 return EXIT_FAILURE ;
15301530}
15311531
1532- #ifdef BENCHMARK_SIEVE
1533- #include <time.h>
1534- #include <sys/time.h>
1535- #define LTM_BILLION 1000000000
1536- static uint64_t gettime (void )
1537- {
1538- struct timespec ts ;
1539- clock_gettime (CLOCK_MONOTONIC , & ts );
1540- return (((uint64_t )ts .tv_sec ) * LTM_BILLION + (uint64_t )ts .tv_nsec );
1541- }
1542- static void print_timer (const char * s , const uint64_t start , const uint64_t stop )
1543- {
1544- printf ("%s%" PRIu64 " min %" PRIu64 " sec %" PRIu64 " ms %" PRIu64 " usec %" PRIu64 " nsec\n" , s ,
1545- ((stop - start )/LTM_BILLION ) / 60 ,
1546- ((stop - start )/LTM_BILLION ) % 60 ,
1547- ((stop - start )/(LTM_BILLION /1000 ))%1000 ,
1548- ((stop - start )/(LTM_BILLION /1000000 ))%1000 ,
1549- (((stop - start )%LTM_BILLION )%1000 )
1550- );
1551- }
1552- #endif
15531532static int test_mp_is_small_prime (void )
15541533{
15551534 mp_sieve sieve ;
@@ -1571,25 +1550,10 @@ static int test_mp_is_small_prime(void)
15711550 };
15721551 bool result ;
15731552
1574- #ifdef BENCHMARK_SIEVE
1575- uint64_t startgt , stopgt ;
1576- #endif
1577-
15781553 mp_sieve_init (& sieve );
15791554
15801555 test_size = (int )(sizeof (to_test )/sizeof (mp_sieve_prime ));
15811556
1582- #ifdef BENCHMARK_SIEVE
1583- startgt = gettime ();
1584- if ((e = mp_is_small_prime ((mp_sieve_prime )(153u ), & result , & sieve )) != MP_OKAY ) {
1585- fprintf (stderr ,"mp_is_small_prime failed: \"%s\"\n" ,mp_error_to_string (e ));
1586- goto LTM_ERR ;
1587- }
1588- stopgt = gettime ();
1589- printf ("Building base sieve and checking once: %" MP_SIEVE_PR_UINT ": " , (mp_sieve_prime )(153u ));
1590- print_timer ("" ,startgt , stopgt );
1591- #endif
1592-
15931557 for (i = 0 ; i < test_size ; i ++ ) {
15941558 if ((e = mp_is_small_prime (to_test [i ], & result , & sieve )) != MP_OKAY ) {
15951559 fprintf (stderr ,"mp_is_small_prime failed: \"%s\"\n" ,mp_error_to_string (e ));
@@ -1617,9 +1581,7 @@ static int test_mp_next_small_prime(void)
16171581 mp_int primesum , t ;
16181582 mp_err e ;
16191583 int i , test_size ;
1620- #ifdef BENCHMARK_SIEVE
1621- uint64_t startgt , stopgt ;
1622- #endif
1584+
16231585 /* Jumping wildly to and fro */
16241586 mp_sieve_prime to_test [] = {
16251587 52 , 137 , 153 , 179 , 6 , 153 , 53 , 132 , 150 , 65 ,
@@ -1639,20 +1601,13 @@ static int test_mp_next_small_prime(void)
16391601 961126169 , 1057886083 , 1222702081 , 1017450823 ,
16401602 1019879761 , 72282701 , 2048787577 , 2058368113
16411603 };
1642-
1643- #ifdef BENCHMARK_SIEVE
1644- const char * primesum_32 = "425649736193687430" ;
1645- #else
16461604 const char * primesum_32 = "202259606268580" ;
1647- #endif
1605+
16481606 mp_sieve_init (& sieve );
16491607
16501608 test_size = (int )(sizeof (to_test )/sizeof (mp_sieve_prime ));
16511609
16521610 for (i = 0 ; i < test_size ; i ++ ) {
1653- #ifdef BENCHMARK_SIEVE
1654- startgt = gettime ();
1655- #endif
16561611 if ((e = mp_next_small_prime (to_test [i ], & ret , & sieve )) != MP_OKAY ) {
16571612 fprintf (stderr ,"mp_next_small_prime failed with \"%s\" at index %d\n" ,
16581613 mp_error_to_string (e ), i );
@@ -1663,23 +1618,11 @@ static int test_mp_next_small_prime(void)
16631618 (unsigned long )to_test [i ], (unsigned long )ret , (unsigned long )tested [i ]);
16641619 goto LBL_ERR ;
16651620 }
1666- #ifdef BENCHMARK_SIEVE
1667- stopgt = gettime ();
1668- printf ("Single random access for prime: %*" MP_SIEVE_PR_UINT ": " , 10 , ret );
1669- print_timer ("" ,startgt , stopgt );
1670- #endif
16711621 }
16721622
16731623 DOR (mp_init_multi (& primesum , & t , NULL ));
1674- #ifdef BENCHMARK_SIEVE
1675- startgt = gettime ();
1676- #endif
16771624
1678- #ifdef BENCHMARK_SIEVE
1679- for (p = 0ul ; ret < (mp_sieve_prime )MP_SIEVE_BIGGEST_PRIME ;) {
1680- #else
16811625 for (p = 4293918720lu ; ret < (mp_sieve_prime )MP_SIEVE_BIGGEST_PRIME ;) {
1682- #endif
16831626 DO (mp_next_small_prime (p , & ret , & sieve ));
16841627 p = ret + 1u ;
16851628#ifdef MP_64BIT
@@ -1689,13 +1632,6 @@ static int test_mp_next_small_prime(void)
16891632#endif
16901633 DO (mp_add (& primesum , & t , & primesum ));
16911634 }
1692-
1693- #ifdef BENCHMARK_SIEVE
1694- stopgt = gettime ();
1695- printf ("Sum of all primes between 0 and %" MP_SIEVE_PR_UINT " = " , (mp_sieve_prime )MP_SIEVE_BIGGEST_PRIME );
1696- DO (mp_fwrite (& primesum , 10 , stdout ));
1697- print_timer (", computed in \n" ,startgt , stopgt );
1698- #endif
16991635 printf ("Primesum computed: " );
17001636 DO (mp_fwrite (& primesum , 10 , stdout ));
17011637 puts ("" );
0 commit comments