On Sunday, October 7, 2012 11:15:28 PM UTC+2, Marc Dzaebel wrote:
>
> *apply *is slow. However you can increase performance by 60% with the 
> following macro, if you have a fixed length in S. 


> [...]
>
> (let[t(fn[](*apply       *+ '(1 2 3 4 5 6 7 8 9 10)))] (time(dotimes [_ 
> 1000000] (t)))) ; ~680 msec
> (let[t(fn[](*applyn *10 + '(1 2 3 4 5 6 7 8 9 10)))] (time(dotimes [_ 
> 1000000] (t)))) ; ~220 msec
>

Interesting, even though it's impractical to use it on an already defined 
list. Usually, I want to work with list or sequences I've generated with 
other functions, like so:

(let[t(fn[](applyn 10 + (range 1 11)))] (time(dotimes [_ 1000000] (t)))) ; 
~ 950 msec
(let[t(fn[](applyn + (range 1 11)))] (time(dotimes [_ 1000000] (t)))) ; ~ 
940 msec

(In addition, apply is in this case is not really what you want to do with 
this list - you should use reduce instead.)
(let[t(fn[](reduce + (range 1 11)))] (time(dotimes [_ 1000000] (t)))) ; ~ 
890 msec

Curiously, if I vec the result, I get a completely different answer:

(let[t(fn[](applyn 10 + (vec (range 1 11))))] (time(dotimes [_ 1000000] 
(t)))) ; ~ 1330 msec
(let[t(fn[](apply + (vec (range 1 11))))] (time(dotimes [_ 1000000] (t)))) 
; ~ 1410 msec
(let[t(fn[](reduce + (vec (range 1 11))))] (time(dotimes [_ 1000000] (t)))) 
; ~ 1340 msec

This is hardly any scientific test though, so I'll leave the conclusion to 
someone with a more rigorous testing scheme.

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