Thank you very much for the help ! On Jul 24, 2:30 pm, Chas Emerick <cemer...@snowtide.com> wrote: > A couple of thoughts: > > You should be using 1.3.0-beta1 of Clojure 1.3 -- anything with > -master-SNAPSHOT is woefully out of date at > this point.
Damned, I thought -master-SNAPSHOT was as snapshot of the current HEAD. Thanks for pointing that out. > ... > However, I wouldn't expect (much of) a speedup from those minor tweaks. > First, if that reduce with the >`compute-step` fn is your hot loop, reduce > will box you into oblivion. At least until primitives work across > applications of HOFs, you'll need to unroll that by hand. Second, you're > destructuring with `[next-put-value > next-call-value]`. Destructuring is convenient and usually not a bottleneck, > but it often is if you're > attempting to avoid boxing overhead: what you have now is boxing the two > values you're binding, and then > creating a vector to hold them, and then pulling that vector apart to get to > the original values. You can just > move your conditional out of the let's binding vector, and use it to choose > between two recur paths: >... I had a wallclock time of 54094 msecs and two relection warnings about the loop variables (plus the unimportnant one about the swap! return type). I first followed your advice to remove destructuring and was surprised to see that the warnings for the two loop variables had disappeared ! However, the speedup was indeed minor, down to 50573 msecs. I then removed the reduce as you suggested and went to this inner loop : (loop [put-value 0. call-value 0.] (if (neg? (swap! n-iters-todo dec)) [put-value call-value] (let [delta-price (- strike-price (loop [price stock-price s n-steps] (if (== s 0) price (recur (* price (+ 1. (* (.nextDouble double-normal-rng 0. volatility) coeff) (* risk- free-rate (/ years-to-maturity n-steps)))) (dec s)))))] (if (pos? delta-price) (recur (+ put-value delta-price) call-value) (recur put-value (- call-value delta-price))))))) Quiet ugly by Clojure standard I confess, but *incredibly* efficient with a run time down to 5993 msecs ! (No missing digit: a near x10 speedup !) : faster than both my C++ OpenMP and my C++ 0X multi-threaded implementations ! This is the first time that I witness this (discounting micro benchmarks made on purpose to show off the JIT). Thanks for making this happen :) Best Regards, Bernard -- 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