]> gitweb.factorcode.org Git - factor.git/blob - apps/benchmarks/hashtables.factor
44e0a615ca75f8dff3872490556469ed7037d9a9
[factor.git] / apps / benchmarks / hashtables.factor
1 IN: temporary
2 USING: compiler hashtables kernel math memory namespaces
3 sequences strings test ;
4
5 : hash-bench-step ( hash elt -- )
6     3 random-int {
7         { [ dup 0 = ] [ drop dup rot set-hash ] }
8         { [ dup 1 = ] [ drop swap remove-hash ] }
9         { [ dup 2 = ] [ drop swap hash drop ] }
10     } cond ;
11
12 : hashtable-benchmark ( seq -- )
13     10000 <hashtable> swap 10 [
14         drop
15         [
16             [
17                 hash-bench-step
18             ] each-with
19         ] 2keep
20     ] each 2drop ;
21
22 [ ] [ [ string? ] instances hashtable-benchmark ] unit-test