On Jun 23, 2009, at 11:37 AM, Kyle Schaffrick wrote:

> As an aside, I also notice you prefer 'reduce to 'apply when using
> arithmetic functions, yet I've seen both in the wild. I'm just  
> guessing
> you prefer to make it explicit that you're doing a reduction, but I
> wonder if one is better than another?


That's an interesting question. I just benchmarked 'em and found this:

user> (time (reduce + (range 100000000)))
"Elapsed time: 4724.192 msecs"
4999999950000000

user> (time (apply + (range 100000000)))
"Elapsed time: 3018.139 msecs"
4999999950000000

I would have expected that 'apply would eventually blow up, because in  
Common Lisp there is a maximum number of arguments. My second  
intuition was that if '+/2 is inlined then the reduce should be  
faster, taking advantage of the inlined code. Both my intuitions were  
wrong and it looks like 'apply is notably faster.

—
Daniel Lyons


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