]> gitweb.factorcode.org Git - factor.git/blob - extra/benchmark/hash-sets/hash-sets.factor
factor: trim using lists
[factor.git] / extra / benchmark / hash-sets / hash-sets.factor
1
2 USING: combinators hash-sets kernel literals
3 math math.combinatorics sequences sets ;
4
5 IN: benchmark.hash-sets
6
7 CONSTANT: test-sets $[
8     { 10 100 1,000 10,000 50,000 100,000 }
9     [ <iota> >hash-set ] map dup append
10 ]
11
12 : do-times ( n quot: ( set1 set2 -- set' ) -- )
13     '[ 2dup @ drop ] times 2drop ; inline
14
15 : bench-sets ( seq -- )
16     2 [
17         first2 {
18             [ 3 [ union ] do-times ]
19             [ 5 [ intersect ] do-times ]
20             [ 100,000 [ intersects? ] do-times ]
21             [ 3 [ diff ] do-times ]
22             [ 50 [ set= ] do-times ]
23             [ 25 [ subset? ] do-times ]
24         } 2cleave
25     ] each-combination ;
26
27 : hash-sets-benchmark ( -- )
28     test-sets bench-sets ;
29
30 MAIN: hash-sets-benchmark