Below is a Clojure solution that runs in 8.58 microseconds on my machine. I only did it for the 40, 3 case. Records are linked. The list reduction solution runs in 23.4 and the element recursion in 27.3
--art (defrecord Soldier [val r]) (def v (vec (map #(Soldier. % (inc %)) (range 40)))) (def v2 (assoc v 39 (Soldier. 39 0))) (defn move [v i] (let [r1 (v i) r2 (:r (v (:r r1)))] [(:r (v r2)) (assoc v (:r r1) (Soldier. (:val r1) (:r (v r2))))] )) (defn joe [v] (loop [v v i 0 count 39] (if (zero? count) (inc i) (let [[a b] (move v i)] (recur b a (dec count)))))) (prn (joe v2)) (let [start (System/currentTimeMillis) iterations 100000] (doseq [i (range 100000)] (joe v2)) (let [end (System/currentTimeMillis)] (println (/ (* (- end start) 1000.00) iterations) " microseconds"))) On Aug 18, 12:40 am, Roberto Mannai <roberm...@gmail.com> wrote: > Hello, > I recently stumbled upon this > page:http://java.dzone.com/articles/contrasting-performance > They are comparing several languages (Java, Scala, Python, Erlang, > Clojure, Ruby, Groovy, Javascript), and Clojure rated very badly: > > Object Oriented List Reduction > Element Recursion > Java 1.6 0.637 1.435 > 2.816 > Clojure 1.2.1 - 25.966 > 28.753 > > Maybe the clojure's scripts were not very idiomatic? If some guru > wants to check them, here's the source code: > -https://github.com/dnene/josephus/blob/master/element-recursion/josep... > - https://github.com/dnene/josephus/blob/master/list-reduction/josephus... > > All the best, > Roberto -- 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