On Sun, Nov 30, 2008 at 4:34 AM, Kevin Downey <[EMAIL PROTECTED]> wrote:
> (reduce str [\a \b \c])
> (apply str [\a \b \c])

For the record, 'apply str' is significantly faster because 'str'
creates a StringBuilder when given 2 or more args, and uses that to
build up the string.  Using 'reduce' causes this to happen once for
each item of the seq (minus one), while 'apply' causes a single
StringBuilder to be created and then populated with a tight fn/recur
loop.

user=> (time (dotimes [_ 100] (apply str long-sequence)))
"Elapsed time: 36.130324 msecs"
nil
user=> (time (dotimes [_ 100] (reduce str long-sequence)))
"Elapsed time: 1050.878775 msecs"
nil

--Chouser

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

Reply via email to