/*
FALCON - Benchmarks
FILE: sieve.fal
Timed Sieve of Eratosthenes.
Measures performance how many computational loops are performed
in a given amount of time.
See also "sieve_mt.fal"
-------------------------------------------------------------------
Author: Giancarlo Niccolai
Begin:
-------------------------------------------------------------------
(C) Copyright 2008: the FALCON developers (see list in AUTHORS file)
See LICENSE file for licensing details.
*/
// Config
const SIZE = 8092
const BATCH = 100
const TIME = 30
flags = arrayBuffer( SIZE+1 )
//=========================
// The sieve
//=========================
function sieve()
global count
flags.fill(0)
for i in [1:SIZE+1]
if flags[i]: continue
prime = 2 * i + 1
start = prime + i
for k in [start:SIZE+1:prime]
flags[k] = 1
end
end
count += i
end
//=========================
// Main code
//=========================
count = 0
cycles = 0
t = seconds()
//while seconds() < t + TIME // Test for TIME (30) seconds
for iter in [0:BATCH]
sieve()
end
cycles += BATCH
//end
t = seconds() - t
f = Format( ".3" )
> f.format( t ), " seconds."
> count, " sieves."
> f.format(count / t), " sieves per second"
|