Thanks, yes, the version starting with 0.0 in the loop (rather than 0) does run faster. In my case, about 13% faster (19.7 seconds -- for the code you pasted below, with *unchecked-math*, type hints and starting x of 0.0 -- vs 22.7 seconds for my original version). But if you start with x of 0 (integer), the type-hinted version runs notably slower. In all cases, though, at least you get the same final answer... (-;
So I don't see that 50% speedup you're seeing, but I do see improvement. I'm on Clojure 1.5.1, and Java 1.7.0_51 on OS X 10.8.5, running in an nREPL (cider) in Emacs. Possibly other JDK versions have more optimizations? Thanks Glen. On Feb 5, 2014, at 10:56 PM, David Nolen <[email protected]> wrote: > (set! *unchecked-math* true) > (defn g ^double [^double x] (+ (Math/sin (* 2.3 x)) (Math/cos (* 3.7 x)))) > (time (loop [i 100000000 x 0.0] (if (pos? i) (recur (dec i) (g x)) x))) > > This is nearly 50% faster than the original version on my machine. Note that > x is bound to 0.0 in the loop, which allows the optimized g to be invoked. > > > On Wed, Feb 5, 2014 at 4:41 PM, Glen Fraser <[email protected]> wrote: > Thanks to both of you for these suggestions, they're good to know. In my > specific case, setting the *unchecked-math* flag true did indeed speed things > up slightly (by about 6%). The other change, though, with the double type > hints (I assume that's what those are), actually ran notably slower (over 20% > slower!). > > Glen. > > On Feb 5, 2014, at 8:13 PM, David Nolen <[email protected]> wrote: > >> Also: >> >> (defn g ^double [^double x] (+ (Math/sin (* 2.3 x)) (Math/cos (* 3.7 x)))) >> >> >> On Wed, Feb 5, 2014 at 2:07 PM, Alex Miller <[email protected]> wrote: >> Others have answered with many useful bits but I would mention that it would >> possibly make a significant performance difference if you added this to your >> code: >> >> (set! *unchecked-math* true) >> >> > -- 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.
