Yoshinori Kohyama <yykohy...@gmail.com> writes: Hi!
> Sorry for mere my continued report. No apologies needed. It's very interesting. > Instead of reversing operands, I tried accumulating operators and > reversing and applying it when stopping. > https://gist.github.com/2896939 > It doesn't consume stack. (but heap...) Very interesting again. The theory should be that you iterate the collection only once to create a big composition of function that already know one of their args. However, you have to reverse the list of functions, which destroys the theoretical benefit. user> (time (reduce-right - (range 2000000))) "Elapsed time: 6375.358049 msecs" -1000000 So use a vector and conjoin to the tail instead of consing to a list that later needs to be reversed. https://gist.github.com/2908767 With that, I get this result: user> (time (reduce-right - (range 2000000))) "Elapsed time: 3352.812468 msecs" -1000000 But still my reverse-the-collection-and-then-reduce-it approach is still much faster, although it has to iterate the collection twice. user> (time (foldr - 0 (range 2000000))) "Elapsed time: 831.605479 msecs" -1000000 I'm not exactly sure why, but I'd guess the allocation overhead for 2 million partial functions is rather expensive. Bye, Tassilo -- 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