I have these strange times in a microbenchmark that compares the time
to run hash-ref when the key is in the hash and when it is not there:

;---
#lang racket/base
(define hash0 #hash((0 . #t)))
(define hash1 #hash((1 . #t)))

(for ([rep (in-range 5)])
  (display "h0: ")
  (time
   (for ([i (in-range 10000000)])
     (hash-ref hash0 0 #f))
   (void))

  (display "h1: ")
  (time
   (for ([i (in-range 10000000)])
     (hash-ref hash1 0 #f))
   (void))
)
;---

Typical run times, sorted by cpu time

found:
h0: cpu time: 3775 real time: 3798 gc time: 0
h0: cpu time: 3900 real time: 3936 gc time: 0
h0: cpu time: 3916 real time: 4009 gc time: 0
h0: cpu time: 3947 real time: 4006 gc time: 0
h0: cpu time: 3978 real time: 4096 gc time: 0

not found:
h1: cpu time: 2278 real time: 2270 gc time: 0
h1: cpu time: 2293 real time: 2360 gc time: 0
h1: cpu time: 2434 real time: 2462 gc time: 0
h1: cpu time: 2449 real time: 2506 gc time: 0
h1: cpu time: 2589 real time: 2682 gc time: 0

The "not found" version is 40% faster. I tried a few variation with
small hashes and I got similar results.

I expected that both have roughly the same time (or that the "found"
version were slightly faster).

Gustavo

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to