home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / pc / source / tile.lzh / tile.1 / tst / byte-sieve.tst < prev    next >
Encoding:
Text File  |  1990-07-26  |  1.0 KB  |  42 lines

  1. .( Loading Byte Magazine Sieve benckmark...) cr
  2.  
  3. \ This is the "standard" sieve benchmark as published in Byte Magazine.
  4. \ The algorithm is wrong in the sense that it gives an incorrect count
  5. \ of the number of primes.  That doesn't affect it's usefulness as a
  6. \ benchmark.
  7. \
  8. \ This benchmark tends to be relatively insensitive to the efficiency
  9. \ of "nesting" (calling a colon definition), since it is implemented
  10. \ almost entirely with very low level words, which are code words in
  11. \ most Forth implementations.  This is reasonably fair, however, since
  12. \ studies have shown that in many Forth programs, code words get
  13. \ executed on the order of 8 times more frequently than colon
  14. \ definitions.
  15.  
  16. decimal
  17. 8192 constant size
  18. create flags size allot
  19.  
  20. : do-prime ( -- )
  21.   flags size 1 fill
  22.   0 size 0 do
  23.     flags i + c@
  24.     if i dup + 3 + dup i +
  25.       begin
  26.     dup size <
  27.       while
  28.     0 over flags + c!
  29.     over +
  30.       repeat
  31.       2drop 1+
  32.     then
  33.   loop
  34.   1899 = not abort" prime: wrong result"
  35. ;
  36.  
  37. : byte-sieve ( -- )
  38.   10 0 do do-prime loop
  39. ;
  40.  
  41. forth only
  42.