On 16 November 2016 at 03:39, Didier <didi...@gmail.com> wrote: > > Currently, this takes about 30s in Clojure, while it only takes around 3s > for OCaml, Rust and F#. > > From what I see, the differences between my code and theirs are: > > - Lack of a Point struct, I'm just using a vector. > - They use a mutable set, I don't. > - They overrode Hashing for their point struct, as well as equality. I > rely on Clojure's default hashing, and vector equality. > > I'm not sure if any of these things should really impact performance that > much though. And what I could do in Clojure if I wanted to improve it. > It's the mutability of the set that's causing the greatest performance impact. You can't substitute in an immutable data structure into an algorithm that makes heavy use of a mutable structure, and expect it to have the same performance.
Something like this is more faithful to the original F# benchmark you posted: (defn nth* [n p] (loop [n n, s1 (java.util.HashSet. [p]), s2 (java.util.HashSet.)] (if (= n 0) s1 (let [s0 (java.util.HashSet.)] (letfn [(add [p] (when-not (or (.contains s1 p) (.contains s2 p)) (.add s0 p)))] (doseq [p s1] (iter-neighbors add p)) (recur (dec n) s0 s1)))))) - James > > Any Help? > > > Thanks. > > -- > 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 > --- > You received this message because you are subscribed to the Google Groups > "Clojure" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to clojure+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- 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 --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.