On Tue, May 3, 2011 at 2:51 PM, Ken Wesson <kwess...@gmail.com> wrote:

> It's optimizing your loop away, or else you're using ridiculously
> powerful hardware.
>
> user=> (time (dotimes [_ 1000000] (Math/ceil (rand))))
> "Elapsed time: 142.86748 msecs"
> nil


Maybe, maybe not:

(do
  (set! *unchecked-math* true)
  (let [nums (double-array (repeatedly 1e3 rand))]
    (dotimes [_ 10]
      (time
       (dotimes [i 1e8] (Math/ceil (double (aget nums (rem i 1e3)))))))))
"Elapsed time: 1405.835 msecs"

(do
  (set! *unchecked-math* true)
  (let [nums (double-array (repeatedly 1e3 rand))]
    (dotimes [_ 10]
      (time
       (dotimes [i 1e8] (double (aget nums (rem i 1e3))))))))
"Elapsed time: 1409.305 msecs"

Given that the i7 is far into the gigaflops territory, I don't find this
particularly surprising. But I'm not a hardware architecture expert by any
means nor an expert of what kind of magic the JVM can do.

David

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