[plt-scheme] hash-has-key?

From: Eli Barzilay (eli at barzilay.org)
Date: Fri Mar 27 21:29:37 EDT 2009

The different available methods have *very* different runtimes.  On my
machine, I'm getting more than a 200x difference between the two
extremes -- for this code:

  (define t (make-hasheq))
  (for ([i (in-range 0 1000000 2)]) (hash-set! t i #t))
  (define (try hash-has-key?)
    (for/fold ([sum 0]) ([i (in-range 1000000)])
      (if (hash-has-key? t i) (add1 sum) sum)))

I'm getting these numbers (using 10 runs for each, averaging the
middle 6):

  let/cc:     cpu time: 24715ms = 24424ms + 291ms gc; real time: 24720ms
  handlers:   cpu time: 15786ms = 15726ms +  60ms gc; real time: 15789ms
  let/ec:     cpu time:   405ms =   402ms +   3ms gc; real time:   405ms
  unique-val: cpu time:   110ms =   110ms +   0ms gc; real time:   110ms

          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!

Posted on the users mailing list.