		   ---------------------------
		   -- Prime Sieve Benchmark --
		   -- "Shootout" Version    --
		   ---------------------------
-- usage:
--     exw sieve8k 90000

without type_check
include get.e


constant SIZE = 8192 

constant ON = 1, OFF = 0

procedure main()
    integer count, iterations
    sequence flags, cmd
    object arg
    
    cmd = command_line()
    iterations = 1
    if length(cmd) = 3 then
	arg = value(cmd[3])
	if arg[1] = GET_SUCCESS then
	    iterations = arg[2]
	end if
    end if
    
    for iter = 1 to iterations do
	count = 0
	flags = repeat(ON, SIZE)
	for i = 2 to SIZE do
	    if flags[i] then
		for k = i + i to SIZE by i do
		    flags[k] = OFF
		end for 
		count += 1
	    end if
	end for
    end for
    printf(1, "Count: %d\n", count)  -- 1028
end procedure

puts(1, "Prime Sieve Benchmark\n")

atom t
t = time()  -- start timer
    
main()

t = time() - t -- end timer

printf(1, "time: %.2f\n", t)

if getc(0) then  -- wait for key press
end if

