[plt-scheme] hash-has-key?

From: Henk Boom (henk at henk.ca)
Date: Fri Mar 27 22:46:53 EDT 2009

2009/3/27 Eli Barzilay <eli at barzilay.org>:
> 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

Ah, thanks for the comparison, I had no idea that the difference
between cc and ec was so big. This function does feel like something
that should be provided as a primitive, though, since hash-ref
obviously has to do this test internally.

    Henk


Posted on the users mailing list.