More importantly than any of these things, he is hanging onto the head of a very, very large sequence with (def lazytri (map triangle (range))). This will lead to serious memory pressure, and perhaps eventually a slowdown as this sequence takes up all the memory in his app and the GC strains to make a tiny bit of room for other temporary objects. Instead of defining it and then immediately using it, he should simply inline its definition into its use, so that the GC is able to free up the bits of it that are no longer in use.
On Thursday, June 20, 2013 7:23:43 AM UTC-7, Meikel Brandmeyer (kotarak) wrote: > > Hi, > > Am Donnerstag, 20. Juni 2013 15:19:40 UTC+2 schrieb John Holland: >> >> (defn triangle [n] (reduce + (range n))) >> (def lazytri (lazy-seq (map triangle (range)))) >> >> > Some quick idea: here is a major difference in your clojure and your java > implementation. You always recompute the whole sum for each step. While you > only increase a counter in the java version. A better lazytri > implementation would be: > > (def lazytri (reductions + (range 1 Long/MAX_VALUE))) > > You don't use sqrt in your clojure version? inc is faster than (+ 1 ...). > zero? is faster than (= 0 ...). > > Kind regards > Meikel > > -- -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to [email protected] Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to [email protected] 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 [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
