' PRIME SIEVE BENCHMARK
BATCH = 50
BENCHTIME = 15
SIZE = 500
FUNCTION sieve
    count = 0
    FOR f = 1 TO SIZE
	flags[f] = TRUE
    NEXT f
    FOR i = 1 TO SIZE
	IF flags[i]= TRUE THEN
	    prime = i + i + 1
	    FOR k = i + prime TO SIZE STEP prime
		flags[k] = FALSE
	    NEXT k
	    count += 1
	END IF
    NEXT i
    sieve = count
END FUNCTION



PRINT "\nprime sieve benchmark ...\n"

cycles = 0
t = NOW
e = NOW + BENCHTIME
WHILE NOW < e
    FOR b = 1 TO BATCH
	IF sieve() <> 167 THEN
            print sieve
	    PRINT "whoops"
	END IF
    NEXT b
    cycles = cycles + BATCH
WEND
t1 = now
PRINT cycles/(t1-t), " Sieves per second\n"
t=0
FOR b = 1 TO SIZE
    IF flags[b] THEN
	PRINT b*2+1,","
        t+=1
        if t=16 then
          print "\n"
          t=0
        end if
    END IF
NEXT b
print "\n"
STOP



