vile / bench / native / hashtable-count-1k.scm
12 lines · 12 sloc · 572 bytes · 76646891b77a3d5c6af4a1e42b122cd61dc1654b
Raw
1(define (benchmark seed)
2 (let ((limit (+ 1000 seed)) (h (make-eqv-hashtable)))
3 (let fill ((n 0))
4 (if (< n limit)
5 (begin (hashtable-set! h (modulo n 256) (+ 1 (hashtable-ref h (modulo n 256) 0))) (fill (+ n 1)))))
6 (let sum ((i 0) (acc 0))
7 (if (= i 256) acc (sum (+ i 1) (+ acc (hashtable-ref h i 0)))))))
8(define (run-batch count)
9 (let loop ((left count) (seed 0))
10 (if (= left 0) 1000
11 (if (= (benchmark seed) (if (= seed 0) 1000 (if (= seed 1) 1001 (if (= seed 2) 1002 1003))))
12 (loop (- left 1) (if (= seed 3) 0 (+ seed 1))) #f))))
13