Is there some reason why accessing the values in a type (from deftype)
should be slower than for a record?  The type seems to be very fast to
instantiate, but slow to access.

(I was just playing around, trying to get a feel for the relative
performance characteristics of types records and maps.  )

user> (defrecord testRec [a b c])
user.testRec
user> (deftype testType [a b c])
user.testType

The results for instantiation were roughly in a pattern that I would
have expected:

user> (time (dotimes [_ 1000000] (hash-map :a 1 :b 1 :c 1)))
"Elapsed time: 973.872 msecs"
nil
user> (time (dotimes [_ 1000000] (new testRec 1 1 1)))
"Elapsed time: 46.315 msecs"
nil
user> (time (dotimes [_ 1000000] (new testType 1 1 1)))
"Elapsed time: 39.562 msecs"
nil

For accessing however, the type seemed inordinately slow:

user> (def myhash {:a 1 :b 2 :c 3})
#'user/myhash
user> (def myRec (new testRec 1 2 3))
#'user/myRec
user> (def myType (new testType 1 2 3))
#'user/myType
user> (time (dotimes [_ 10000000] (:a myhash)))
"Elapsed time: 298.436 msecs"
nil
user> (time (dotimes [_ 10000000] (:a myRec)))
"Elapsed time: 165.879 msecs"
nil
user> (time (dotimes [_ 10000000] (.a myType)))
"Elapsed time: 28100.919 msecs"
nil

I don't pretend that these are at all rigorous benchmarks, but I'm
curious where the apparent overhead comes from in accessing a value in
a type object.

Rob

p.s. For what it's worth, I started the REPL with the -server flag.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to