I've double checked on my machine (Vista. JVM 6. Clojure 1.1.0). Clojure's sort is is 4 to 5 times slower than sorted-vec2 Maybe somebody with a Vista machine double check this?
On Jan 3, 5:51 pm, ianp <ian.phill...@gmail.com> wrote: > > More findings: The reason that the Clojure's original sort is 8 times > > slower > > I don’t see that on my machine. I’m running 1.1.0-master-SNAPSHOT with > Apple’s Java 6 VM in case that has anything to do with it, but here's > what I get (after running the tests several times to warm up hotspot): > > user=> (def v (vec (take 10000 (repeatedly #(rand-int 100000))))) > > user=> (time (dotimes [_ 1000] (sort v))) > "Elapsed time: 4376.471 msecs" > > user=> (defn sorted-vec [coll] > (let [a (into-array coll)] > (java.util.Arrays/sort a) > (vec a))) > user=> (time (dotimes [_ 1000] (sorted-vec v))) > "Elapsed time: 3254.371 msecs" > > user=> (defn sorted-vec-2 [coll] > (let [a (to-array coll)] > (java.util.Arrays/sort a) > (vec a))) > user=> (time (dotimes [_ 1000] (sorted-vec-2 v))) > "Elapsed time: 2599.63 msecs" > > So sorted-vec is faster, but not an order of magnitude, and sorted- > vec-2 is faster again. > > Another alternative that may be worth considering is leaving the data > in the array and using aget to access elements (this should give you O > (1) access times vs. O(log32N) AFAIK). This may be a solution if > you're not mutating the data in the array, but I'd be careful about > this optimisation unless it really gets a large speed boost for your > code. -- 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