local function prequire(name) local success, result = pcall(require, name); return success and result end
local bench = script and require(script.Parent.bench_support) or prequire("bench_support") or require("../bench_support")
function test()
function gen (n)
return coroutine.wrap(function ()
for i=2,n do coroutine.yield(i) end
end)
end
function filter (p, g)
return coroutine.wrap(function ()
while 1 do
local n = g()
if n == nil then return end
if n % p ~= 0 then coroutine.yield(n) end
end
end)
end
local ts0 = os.clock()
for loops=1,100 do
N = 1000
x = gen(N)
while 1 do
local n = x()
if n == nil then break end
x = filter(n, x)
end
end
local ts1 = os.clock()
return ts1-ts0
end
bench.runCode(test, "sieve")