<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sun, Apr 27, 2014 at 7:23 PM, Niklas Hambüchen <span dir="ltr"><<a href="mailto:mail@nh2.me" target="_blank">mail@nh2.me</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
I've just uploaded my benchmarks to <a href="https://github.com/nh2/loop" target="_blank">https://github.com/nh2/loop</a>.<br>
<br>
Please take a look. There are some interesting results.<br>
<br>
<br>
The first thing I don't understand at all is:<br>
<br>
<br>
<a href="http://htmlpreview.github.io/?https://github.com/nh2/loop/blob/master/results/bench.html" target="_blank">http://htmlpreview.github.io/?https://github.com/nh2/loop/blob/master/results/bench.html</a><br>
<br>
See how w32/loop and w32/unsafeLoop are equally fast. Then look at<br>
<br>
<br>
<a href="http://htmlpreview.github.io/?https://github.com/nh2/loop/blob/master/results/bench-traverse-w32.html" target="_blank">http://htmlpreview.github.io/?https://github.com/nh2/loop/blob/master/results/bench-traverse-w32.html</a><br>

<br>
Here I run the same thing over the whole of Word32.<br>
See how `loop` is faster here than `unsafeLoop`? How does that make sense?<br></blockquote><div><br></div><div>Huh?  In the comments you wrote:</div><div><br></div><div><pre style="font-family:Consolas,'Liberation Mono',Courier,monospace;font-size:12px;margin-top:0px;margin-bottom:0px;color:rgb(51,51,51);line-height:18px">
<div class="" id="LC47" style="padding-left:10px;height:18px"><span class="" style="color:rgb(153,153,136);font-style:italic">-- Note that some types (e.g. Word32) have bounds checks even for</span></div><div class="" id="LC48" style="padding-left:10px;height:18px">
<span class="" style="color:rgb(153,153,136);font-style:italic">-- `toEnum`.</span><span style="color:rgb(34,34,34);font-family:arial;font-size:small;line-height:normal"> </span></div></pre></div><div><br></div><div>Doesn't that explain it?  For Int, toEnum/fromEnum is a noop, but on Word32 it's not.</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
Next thing:<br>
<br>
It seems that V.enumFromTo and V.fromList are actually the same:<br>
<br>
<br>
<a href="http://hackage.haskell.org/package/vector-0.10.9.1/docs/src/Data-Vector-Fusion-Stream-Monadic.html#enumFromTo" target="_blank">http://hackage.haskell.org/package/vector-0.10.9.1/docs/src/Data-Vector-Fusion-Stream-Monadic.html#enumFromTo</a><br>

<br>
However in my benchmark, at least for `Int`, the performance is<br>
different - am I overlooking something?<br></blockquote><div><br></div><div>Probably with V.fromList, the list gets floated out?  Just guessing, check the core!</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

<div class=""><br>
<br>
On 28/04/14 01:34, John Lato wrote:<br>
> It can make a difference in that, with unboxed vectors, the compiler can<br>
> statically determine that it is able to use unboxed values, and<br>
> therefore is more likely to do so.  Having finally broken down and run<br>
> some tests, I can report that on my system using V.enumFromTo with<br>
> unboxed vectors results in the same performance as the hand-written loop.<br>
<br>
</div>I cannot see a difference between Vector.enumFromTo and<br>
Vector.Unboxed.enumFromTo in my benchmark.<br>
<br>
Vector.enumFromTo is as fast as the hand-written loop, but only for<br>
`Int`. For `Word32`, it is 5 times slower. Any idea why?<br></blockquote><div><br></div><div>Ahh, you made me look at the core again.  I think this is related to your observation about V.enumFromTo being the same as V.fromList.  With Word32 the generated core shows that this goes via a list representation instead of a nice loop.  Which makes me suspect there's some RULE that applies to Stream.enumFromTo that is firing in the first case but not the second.  And if I build both versions with -ddump-rule-firings, indeed I see that the Int version has</div>
<div><pre style="color:rgb(0,0,0)">Rule fired: enumFromTo<Int> [Stream]<span style="color:rgb(34,34,34);font-family:arial"> </span></pre></div><div>With nothing comparable for the Word32 version.  I'd imagine if you grep for that in the Vector sources, you'd find something interesting.</div>
<div><br></div><div>The EnumFromN version does not seem to suffer from this (but again it's necessary to evaluate the argument).</div></div></div></div>