On IRC we were discussing the behavior of "into", and this lead us to dive into core.clj to look at its implementation. We discovered that it was not implemented with reduce, which would produce the same behavior, and we also discovered that implementing it with reduce may have a performance advantage.
I ran some preliminary benchmarks of the two algorithms. While the performance differences may not be that drastic, using reduce may improve readability and maintainability. My implementation using (reduce conj to from) : (dotimes [_ 10] (time (reduce + (my-into [] (range 1000000))))) "Elapsed time: 874.035953 msecs" "Elapsed time: 666.351601 msecs" "Elapsed time: 644.997897 msecs" "Elapsed time: 692.347375 msecs" "Elapsed time: 618.038741 msecs" "Elapsed time: 635.004044 msecs" "Elapsed time: 645.681234 msecs" "Elapsed time: 644.015174 msecs" "Elapsed time: 571.041487 msecs" "Elapsed time: 663.759128 msecs" Using the built-in clojure into function on the same range: (dotimes [_ 10] (time (reduce + (into [] (range 1000000))))) "Elapsed time: 950.165515 msecs" "Elapsed time: 877.305951 msecs" "Elapsed time: 1077.845426 msecs" "Elapsed time: 747.000597 msecs" "Elapsed time: 718.648507 msecs" "Elapsed time: 691.206218 msecs" "Elapsed time: 744.17943 msecs" --~--~---------~--~----~------------~-------~--~----~ 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 clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---