On Jul 23, 4:06 pm, Dmitry Gutov <raa...@gmail.com> wrote: > Ahem. > > Here is a more idiomatic version that runs under half a second, no > annotations required.
I did that from the beginning, but as I really needed 4e6 and not 1e5 elements, that map got very big. And I didn't remember the argument to give java more memory. Also I was just curious to see what arrays did to the performance. However, my code that looked like that was slow too. I used Clojure 1.2.0. Are you using 1.3.0? > (def vs (atom {})) > > (defn sk [k] > (if (@vs k) > (@vs k) > (let [ans (if (< k 56) > (- (mod (+ 100003 (- (* k 200003)) (* 300007 k k k)) > 1000000) 500000) > (- (mod (+ (sk (- k 24)) > (sk (- k 55))) 1000000) > 500000))] > (do (swap! vs assoc k ans) > ans)))) > > user> (reset! vs {}) > {} > user> (time (dorun (map sk (range 100000)))) > "Elapsed time: 155.082351 msecs" > nil > > I guess the moral is that the built-in data structures are quite fast, > and reflection is evil. -- 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