Yup, I'm wrong.

According to the profiler (visualvm), doseq/bit-shift-left is spending
over 80% of its time in clojure.lang.Reflector.getMethods, but any
other combination (e.g., dotimes/bsl or doseq/+) doesn't spend any
time there at all.  For 100k iterations, the doseq/bsl hits getMethods
just over 100k times; the other combinations call it 18-27 times.

Something is definitely weird here.

On Sep 30, 9:52 pm, Mark Engelberg <mark.engelb...@gmail.com> wrote:
> On Thu, Sep 30, 2010 at 9:13 PM, ataggart <alex.tagg...@gmail.com> wrote:
> > As with most microbenchmarks you're measuring the test more than the
> > subject.  In the above case the seq generation dominates.
>
> > Compare the following on my machine:
> > user=> (time (doseq [x (range 100000)] (bit-shift-left x 1)))
> > "Elapsed time: 3531.198 msecs"
> > nil
> > user=> (time (dotimes [x 100000] (bit-shift-left x 1)))
> > "Elapsed time: 3.744 msecs"
> > nil
>
> But if you replace the bit-shift-left operation with some other
> arithmetic operation in the doseq expression, it is quite fast, thus
> disproving your assertion that the slowdown is caused by the overhead
> of doseq.  Furthermore, as we've already discussed, type hinting the x
> or removing the inline delcaration from bit-shift-left makes the
> problem go away -- inside the doseq expression.
>
> So, if it is true that range produces objects and dotimes produces
> primitive longs, then I believe that it is the odd interaction between
> bit-shift-left's inlining and long objects (as opposed to primitives)
> that is causing the disparity in your measurements, not something
> inherent in the mechanism of doseq vs dotimes.

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