It looks like most of the overhead is the contracts on the dict functions -- if you switch to using `racket/private/dict` (which has no contracts) the overhead goes down a lot.
Also, using `in-range` and `in-vector` in the implementation of `measure` has a big impact on performance, so I think it's worth doing when measuring. Sam On Wed, Jan 6, 2016 at 10:23 AM, Matthias Felleisen <[email protected]> wrote: > > I ran across the snippet of code below (I turned it into a performance > benchmark) and was amazed at how much slower the code ran after making it > readable with dict!: I am seeing a factor of 20x and 40x depending on what > exactly is run. Can anything be done about this? > > > #lang racket > > (define (create n) > (define i 0) > (define sample (make-vector n)) > (lambda (item) > (set! i (+ i 1)) > (vector-set! sample (if (<= i n) (sub1 i) (quotient n 2)) item) > sample)) > > (define counts (make-vector 10 0)) > > (define-syntax-rule > (measure n d update) > (begin > (collect-garbage) > (collect-garbage) > (collect-garbage) > (time > (for ([i n]) > (define f (create 3)) > (define sample (for/last ([digit 10]) (f digit))) > (for ([d sample]) > update))))) > > ;; I don't want more HO overhead > (define n 1000000) > (measure n d (vector-set! counts d (add1 (vector-ref counts d)))) > (measure n d (dict-update! counts d add1)) > > -- > You received this message because you are subscribed to the Google Groups > "Racket Developers" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/racket-dev/62F7A4E7-4AA2-4F73-9686-C84F2FF52CF7%40ccs.neu.edu. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "Racket Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/racket-dev/CAK%3DHD%2BYr01Zuk3RHnkxE3Q7ah81aYB6ZSVePyk4bWRpBFgFB%3DA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
