[racket] Difference in speed accessing fields of a struct with gen:equal+hash
I added gen:equal+hash to a struct type and noticed that accessing
fields of the struct got slower, even though I never used equal? or
hash functions. Is this expected? And if so what is the cause of it?
#lang racket
(struct foo (x) #:transparent)
(struct bar (x) #:transparent
#:methods gen:equal+hash
[(define (equal-proc x y recur)
(recur (bar-x x) (bar-x y)))
(define (hash-proc x recur) (recur (bar-x x)))
(define (hash2-proc x recur) (recur (bar-x x)))])
(define N 10000000)
(define f (foo 3))
(define b (bar 3))
(for ((j 5))
(time
(for ((i (in-range N)))
(equal? (foo-x f) (foo-x f))))
(time
(for ((i (in-range N)))
(equal? (bar-x b) (bar-x b)))))
My timings showing a 10% slowdown.
cpu time: 296 real time: 296 gc time: 0
cpu time: 334 real time: 334 gc time: 0
cpu time: 297 real time: 297 gc time: 0
cpu time: 340 real time: 340 gc time: 0
cpu time: 303 real time: 302 gc time: 0
cpu time: 340 real time: 339 gc time: 0
cpu time: 292 real time: 292 gc time: 0
cpu time: 327 real time: 326 gc time: 0
cpu time: 291 real time: 291 gc time: 0
cpu time: 323 real time: 322 gc time: 0