Ah! That makes more sense. Yeah, after I forced it to realize the sequence, it turned out that concat was a lot slower than sticking it into an array:
#'user/r > user=> (def coll (range 10000)) > #'user/coll > user=> (def coll-v (into [] coll)) > #'user/coll-v > user=> (time (dotimes [_ r] (count (concat coll '(:a))))) > "Elapsed time: 55803.147526 msecs" > nil > user=> (time (dotimes [_ r] (count (conj coll-v :a)))) > "Elapsed time: 18.591737 msecs" > nil > user=> (time (dotimes [_ r] (count (conj (into [] coll) :a)))) > "Elapsed time: 16224.79319 msecs" > nil > On Friday, February 7, 2014 9:26:05 PM UTC-8, puzzler wrote: > > On Fri, Feb 7, 2014 at 9:08 PM, Travis Moy <[email protected]<javascript:> > > wrote: > >> Surprisingly it looks like (concat coll '(:a)) is faster than (conj >> coll-v :a). That's not really what I would expect; does anybody have a good >> explanation for this? Did I just bork the test somehow, or - I mean, >> obviously concat's pretty fast but I was expecting conj to be on the level. >> In fact, if you convert and then conj it's significantly slower than using >> concat. >> > > concat is lazy, so it's not really doing any work until you try to realize > the sequence -- that's why it is so fast. > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to [email protected] Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
