VolksForth/sources/generic/sieve.fth

34 lines
666 B
Forth
Raw Permalink Normal View History

2020-07-26 11:22:46 +00:00
\ Sieve benchmark
CR .( Loading Sieve Benchmark... ) CR
Onlyforth
: allot ( u --)
dup sp@ here - $180 - u>
abort" no room" allot ;
&8192 Constant size
Create flags size allot
: do-prime ( -- #primes )
flags size 1 fill 0
size 0 DO flags I + c@
IF I 2* 3+ dup I +
BEGIN dup size <
WHILE 0 over flags + c!
over +
REPEAT 2drop 1+
THEN
LOOP ;
: benchmark
do-prime . ." Primzahlen" ;
: .primes size 0 DO flags I + c@
IF I 2* 3+ . THEN ?cr
stop? IF LEAVE THEN LOOP ;
CR .( Start Benchmark ) CR
benchmark CR
.primes CR
.( Benchmark finished ) CR