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

  1. .( Loading Colburn Sieve benchmark...) cr
  2.  
  3. \ This is the "Colburn Sieve" as published in a letter to the editor
  4. \ of Dr. Dobbs' Journal.  It is the same algorithm as the first, but
  5. \ is a better Forth implementation of the algorithm.  It uses a
  6. \ DO .. LOOP in the inner loop instead of  BEGIN .. WHILE .. REPEAT
  7. \ This version is a more fair comparison of Forth in relation to other
  8. \ languages.  For comparisons between different Forth systems, both
  9. \ versions are widely used.  It is necessary to state which version
  10. \ you are using in order for your benchmark to be useful.
  11. \
  12. \ The Colburn Sieve typically runs in about 60% of the time of the
  13. \ Byte sieve.
  14.  
  15. decimal
  16. 8192 constant size
  17. create flags size allot
  18.  
  19. : do-prime ( -- )
  20.   flags  size 1 fill 
  21.   0 size 0 do
  22.     flags i + c@
  23.     if 3 i + i + dup i + size <
  24.       if size flags +
  25.     over i + flags + do
  26.       0 i c! dup
  27.     +loop
  28.       then
  29.       drop 1+
  30.    then
  31.  loop
  32.  1899 = not abort" prime: wrong result"
  33.  
  34. : colburn-sieve ( -- )
  35.   10 0 do do-prime loop
  36. ;
  37.  
  38. forth only
  39.