home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / euphoria / sieve.ex < prev    next >
Text File  |  1994-03-08  |  1KB  |  54 lines

  1.            ---------------------------
  2.            -- Byte Magazine's       --
  3.            -- Prime Sieve Benchmark --
  4.            ---------------------------
  5.  
  6. without type_check -- makes no difference
  7.  
  8. constant BATCH = 5
  9. constant BENCH_TIME = 15
  10.  
  11. constant SIZE = 8191, 
  12.      ON  = 1, 
  13.      OFF = 0
  14.  
  15. sequence flags 
  16.  
  17. function sieve()
  18.     integer prime, start, count, still_prime
  19.  
  20.     count = 0
  21.     flags = repeat(ON, SIZE)
  22.     for i = 1 to SIZE do
  23.         still_prime = flags[i]
  24.         if still_prime then
  25.           prime = i + i
  26.         prime = prime + 1 
  27.         -- printf(1, "%d ", prime)
  28.         start = prime + i
  29.         for k = start to SIZE by prime do
  30.         flags[k] = OFF
  31.         end for 
  32.         count = count + 1
  33.     end if
  34.     end for
  35.     return count
  36. end function
  37.  
  38. atom t, cycles
  39.  
  40. puts(1, "prime sieve benchmark ...\n")
  41. cycles = 0
  42. t = time()
  43. while time() < t + BENCH_TIME do
  44.     for iter = 1 to BATCH do
  45.         if sieve() != 1899 then
  46.             puts(2, "whoops!\n")
  47.         end if
  48.     end for
  49.     cycles = cycles + BATCH
  50. end while
  51. t = time() - t
  52. printf(1, "%6.1f sieves per second\n", cycles / t)
  53.  
  54.