On Thu, Dec 30, 2010 at 4:01 AM, Andreas Kostler <andreas.koestler.le...@gmail.com> wrote: > Oh of course. I apologise. Mark do you mind to lay out how you perform your > benchmarks. > On my system (insertion-sort (into [] (range 10000))) runs for an > unacceptable amount of time (talking ~10s) > That seems to be quite long for sorting an already sorted vector of 10k > elements.
Maybe you're still using your original version with the good insert, but the bad sort? Try this: (defn insert-into [sorted-vec element] (loop [i (count sorted-vec)] (if (and (> i 0) (> (nth sorted-vec (dec i)) element)) (recur (dec i)) (into (conj (subvec sorted-vec 0 i) element) (subvec sorted-vec i))))) (defn insertion-sort [s] (reduce insert-into [] s)) (time (last (insertion-sort (range 10000)))) I get 30ms. -- 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