home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / BDSC / BDSC-1 / SIEVE.CQ / SIEVE.C
Text File  |  2000-06-30  |  1KB  |  45 lines

  1. /*
  2.     Sieve of Eratosthenes benchmark from BYTE, Sep. '81, pg. 186.
  3.     Compile by:
  4.             A>cc1 sieve.c -e1000
  5.     All variables have been made external to speed them up; other than
  6.     that one change, the program is identical to the one used in the BYTE
  7.     benchmark....while they got an execution time of 49.5 seconds and a
  8.     size of 3932 bytes using v1.32 of the compiler,
  9.                 ********
  10.     v1.45 clocks in at  * 15.2 *  seconds with a size of 3718 bytes!
  11.                 ********
  12. */
  13.  
  14. #define TRUE 1
  15. #define FALSE 0
  16. #define SIZE 8190
  17. #define SIZEPL 8191
  18.  
  19. char flags[SIZEPL];
  20. int i,prime,k,count,iter;
  21.  
  22. main()
  23. {
  24.     printf("Hit return to do 10 iterations: ");
  25.     getchar();
  26.  
  27.     for (iter = 1; iter <= 10; iter++) {
  28.         count = 0;
  29.         for (i = 0; i <= SIZE; i++)
  30.             flags[i] = TRUE;
  31.         for (i = 0; i <= SIZE; i++) {
  32.             if (flags[i]) {
  33.                 prime = i + i + 3;
  34.                 k = i + prime;
  35.                 while (k <= SIZE) {
  36.                     flags[k] = FALSE;
  37.                     k += prime;
  38.                 }
  39.                 count++;
  40.             }
  41.         }
  42.     }
  43.     printf("\7\n%d primes.\n",count);
  44. }
  45.