home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
OSK
/
EFFO
/
pd6.lzh
/
TST
/
byte_sieve.tst
< prev
next >
Wrap
Text File
|
1989-12-21
|
1KB
|
41 lines
.( Loading Byte Magazine Sieve benckmark...) cr
decimal
8192 constant size
create flags size allot
\ This is the "standard" sieve benchmark as published in Byte Magazine.
\ The algorithm is wrong in the sense that it gives an incorrect count
\ of the number of primes. That doesn't affect it's usefulness as a
\ benchmark.
\
\ This benchmark tends to be relatively insensitive to the efficiency
\ of "nesting" (calling a colon definition), since it is implemented
\ almost entirely with very low level words, which are code words in
\ most Forth implementations. This is reasonably fair, however, since
\ studies have shown that in many Forth programs, code words get
\ executed on the order of 8 times more frequently than colon
\ definitions.
: do-prime ( -- )
flags size 1 fill
0 size 0 do
flags i + c@
if i dup + 3 + dup i +
begin
dup size <
while
0 over flags + c!
over +
repeat
drop drop 1+
then
loop
1899 = not abort" prime: wrong result" ;
: byte-sieve ( -- )
10 0 do do-prime loop ;
forth only