' Sieve of eratosthenes Benchmark
' Just to prove that you shouldn't use Rapid-Q for math intensive programs

DIM Flags(8190) AS INTEGER
DIM Iter AS INTEGER
DIM I AS INTEGER
DIM Count AS INTEGER
DIM K AS INTEGER
DIM Prime AS INTEGER

PRINT "Sieve - 10 iterations"

FOR Iter = 1 TO 10
  Count = 0
  T! = TIMER

  FOR I = 0 TO 8190
    Flags(I) = 1
  NEXT I

  FOR I = 0 TO 8190
    IF Flags(I) = 1 THEN
       Prime = I + I
       Prime = Prime + 3
       K = I + Prime
       WHILE K <= 8190
         Flags(K) = 0
         K = K + Prime
       WEND
       Count = Count + 1
    END IF
  NEXT I
  PRINT "Iteration "; Iter; ": took "; TIMER - T!; " seconds."
NEXT Iter

