home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / EFFO / pd6.lzh / TST / colburn_sieve.tst < prev    next >
Text File  |  1989-12-21  |  1KB  |  38 lines

  1. .( Loading Colburn Sieve benchmark...) cr
  2.  
  3. decimal
  4. 8192 constant size
  5. create flags size allot
  6.  
  7. \ This is the "Colburn Sieve" as published in a letter to the editor
  8. \ of Dr. Dobbs' Journal.  It is the same algorithm as the first, but
  9. \ is a better Forth implementation of the algorithm.  It uses a
  10. \ DO .. LOOP in the inner loop instead of  BEGIN .. WHILE .. REPEAT
  11. \ This version is a more fair comparison of Forth in relation to other
  12. \ languages.  For comparisons between different Forth systems, both
  13. \ versions are widely used.  It is necessary to state which version
  14. \ you are using in order for your benchmark to be useful.
  15. \
  16. \ The Colburn Sieve typically runs in about 60% of the time of the
  17. \ Byte sieve.
  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. forth only
  38.