From 78685042a4a4c0635c58077981e769be5454a5ce Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Sun, 7 Jun 2015 11:30:04 -0700 Subject: [PATCH] benchmark.sieve: calculating the number of primes in [1,100,000,000]. --- extra/benchmark/sieve/sieve.factor | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 extra/benchmark/sieve/sieve.factor diff --git a/extra/benchmark/sieve/sieve.factor b/extra/benchmark/sieve/sieve.factor new file mode 100644 index 0000000000..b9168b3f8c --- /dev/null +++ b/extra/benchmark/sieve/sieve.factor @@ -0,0 +1,22 @@ +USING: bit-arrays kernel locals math math.functions math.ranges +sequences ; +IN: benchmark.sieve + +:: sieve ( n -- #primes ) + n dup odd? [ 1 + ] when 2/ :> sieve + t 0 sieve set-nth + + 3 n sqrt 2 [| i | + i 2/ sieve nth [ + i sq n i 2 * [| j | + t j 2/ sieve set-nth + ] each + ] unless + ] each + + sieve [ not ] count 1 + ; + +: sieve-benchmark ( -- ) + 100,000,000 sieve 5,761,455 assert= ; + +MAIN: sieve-benchmark