On Jan 18, 2011, at 8:54 PM, Lee Spector wrote:

> Also BTW I saw no clear performance improvement (relative to the overall 
> runtime of my system); some numbers on that are also below.

A perf differential will be seen if slot access is a significant portion of the 
algorithms in question.  IIRC, the difference between struct maps and records 
is that between a map lookup + an array dereference vs. a direct field access 
(e.g. (.slotname foo)) or a function call that performs a direct field access 
(e.g. (:slotname foo)).  Irresponsible benchmarks below.  So, if your usage 
doesn't involve a ton of slot access, you won't see a big perf improvement.

- Chas

-----
Irresponsible microbenchmark:

(defstruct foo [:a :b :c :d])
#'user/foo
(defrecord Bar [a b c d])
user.Bar
(time
  (let [s (struct-map foo 1 2 3 4)]
    (dotimes [x 1e7]
      (:a s)
      (:b s)
      (:c s)
      (:d s))))
"Elapsed time: 4734.852 msecs"
nil
(time
  (let [s (Bar. 1 2 3 4)]
    (dotimes [x 1e7]
      (:a s)
      (:b s)
      (:c s)
      (:d s))))
"Elapsed time: 721.399 msecs"

;; I've not checked this, but I suspect the differential will be even larger 
for structs/records with lots of slots

-- 
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