I've actually tried with and without type hinting and end up with
similar performance numbers.  I haven't tried type hinting the second
execution.

On Feb 18, 7:49 am, Ken Wesson <kwess...@gmail.com> wrote:
> On Fri, Feb 18, 2011 at 7:03 AM, Daniel Werner
>
>
>
> <daniel.d.wer...@googlemail.com> wrote:
> > On Feb 16, 6:20 am, Nick <npatric...@gmail.com> wrote:
> >> (let [  newv1  (time (doall (map (fn [v u I] (+ ^java.lang.Double v (*
> >> 0.5 (+ (* (+ (* 0.04 ^java.lang.Double v) 5) ^java.lang.Double v) 140
> >> (- ^java.lang.Double u) ^java.lang.Double I)))) v u I)))
> >>         newv  (time (doall (map (fn [v u I] (+ v (* 0.5 (+ (* (+ (* 0.04 v)
> >> 5) v) 140 (- u) I)))) newv1 u I)))]
>
> >> I've tried without type hints, with type hints, different ways of
> >> doing the type hints, but I cannot explain the results that I'm
> >> seeing.  With all of the variations I've tried, I've always seen
> >> timing like this:
>
> >> "Elapsed time: 49.876243 msecs"
> >> "Elapsed time: 0.179701 msecs"
>
> >> What am I missing here?  Is the compiler getting some advantage to
> >> executing the same function twice that cannot be gained in the first
> >> execution?
>
> > Since nobody has replied so far: One explanation I could imagine is
> > that your type-hints in the first invocation force the compiler to use
> > object types for all the nitty-gritty calculations, whereas the second
> > invocation is able to use primitives for calculations, having to box
> > them only when the final sequence is produced.
>
> Yes, that's exactly right. Some operators like + Clojure's compiler
> knows to inline and then they don't have to box primitives. The type
> hints force boxing in this case.

-- 
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

Reply via email to