rendered paste body(*
* LANGUAGE : ANS Forth
* PROJECT : Forth Environments
* DESCRIPTION : The Famous Sieve of Eratosthanes, using bits
* CATEGORY : Benchmarks
* AUTHOR : Marcel Hendrix
* LAST CHANGE : Monday, June 04, 2001 11:54 PM, MHX
*)
NEEDS -miscutil
REVISION -bit-sieve "ÄÄÄ SIEVE benchmark Version 1.01 ÄÄÄ"
#1000 =: #times
#8192 =: size
CREATE flags size 8 / CHARS ALLOT
: DO-PRIME flags [ size 8 / ] LITERAL %11111111 FILL
0 size 0 DO flags I
BIT? IF I 2* 3 +
DUP I +
BEGIN DUP size
U< WHILE flags OVER BIT-RESET
OVER +
REPEAT
2DROP 1+
ENDIF
LOOP ;
: PRIMES CR #times DEC. ." iterations." TIMER-RESET
0 #times 0 DO DROP DO-PRIME LOOP
MS? SWAP CR . ." primes found, " DEC. ." ms elapsed." ;
:ABOUT CR ." Sieve (" #times 0 .R ." iterations)"
CR ." Enter PRIMES to run the (bit test) benchmark."
CR ." On AMD Athlon this is only 10% slower than sieve.frt ." ;
.ABOUT -bit-sieve CR
(* End *)