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. I'm not an expert on
Clojure performance though, this is just a guess.

Have you tried type-hinting your second invocation instead of the
first? What do the timings become?

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