]> gitweb.factorcode.org Git - factor.git/blob - extra/benchmark/sieve/sieve.factor
b9168b3f8c908141472d6476779f768fa2a85e8d
[factor.git] / extra / benchmark / sieve / sieve.factor
1 USING: bit-arrays kernel locals math math.functions math.ranges
2 sequences ;
3 IN: benchmark.sieve
4
5 :: sieve ( n -- #primes )
6     n dup odd? [ 1 + ] when 2/ <bit-array> :> sieve
7     t 0 sieve set-nth
8
9     3 n sqrt 2 <range> [| i |
10         i 2/ sieve nth [
11             i sq n i 2 * <range> [| j |
12                 t j 2/ sieve set-nth
13             ] each
14         ] unless
15     ] each
16
17     sieve [ not ] count 1 + ;
18
19 : sieve-benchmark ( -- )
20     100,000,000 sieve 5,761,455 assert= ;
21
22 MAIN: sieve-benchmark