When I change the C++ program into:<div><br></div><div><div><span class="Apple-tab-span" style="white-space:pre">        </span>int n;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>scanf(&quot;%d&quot;, &amp;n);</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>for(i=0; i&lt;n;i++)</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>{</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>sum += i;</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><br></div><div>GCC need 100 milliseconds on my 3.0GHz new Xeon with loop unrolling enabled.&nbsp;</div><div><br></div><div>Without loop unrolling GCC needs about 635ms</div>
<div><br></div><div><div>Visual C++ does it in 577 ms, generating the following code:</div><div><br></div><div><div>loop: add &nbsp; &nbsp; &nbsp; &nbsp;rbx,rax&nbsp;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;inc &nbsp; &nbsp; &nbsp; &nbsp; rax &nbsp;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; cmp &nbsp; &nbsp; &nbsp; rax,rcx&nbsp;</div><div>
&nbsp;&nbsp; &nbsp; &nbsp; jl &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;loop</div><div><br></div></div></div><div>GHC with -O2 -fvia-c (the fastest I could make it) needs</div><div><br></div><div>13075 for the naive sum<br></div><div>2100 ms with sum0<br></div><div>2018 ms using the stream-fusion<br>
</div><div><br></div><div>Interesting to see that the stream-fusion was slower when not doing -fvia-c (more than twice as slow with -O)</div><div><br></div><div>So GHC is about 3 to 4 times slower as Visual C++ / GCC without loop unrolling, which is not too bad since GHC does not perform register optimization and loop unrolling yet no?<br>
</div><div><br></div><div>On Fri, Feb 20, 2009 at 3:44 PM, Achim Schneider <span dir="ltr">&lt;<a href="mailto:barsoap@web.de">barsoap@web.de</a>&gt;</span> wrote:<br></div></div><div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="Ih2E3d">Bulat Ziganshin &lt;<a href="mailto:bulat.ziganshin@gmail.com">bulat.ziganshin@gmail.com</a>&gt; wrote:<br>
<br>
<br>
&gt; execution times:<br>
&gt; &nbsp;sum:<br>
&gt; &nbsp; &nbsp;ghc 6.6.1 -O2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : 12.433 secs<br>
&gt; &nbsp; &nbsp;ghc 6.10.1 -O2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: 12.792 secs<br>
&gt; &nbsp;sum-fast:<br>
&gt; &nbsp; &nbsp;ghc 6.6.1 -O2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : &nbsp;1.919 secs<br>
&gt; &nbsp; &nbsp;ghc 6.10.1 -O2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: &nbsp;1.856 secs<br>
&gt; &nbsp; &nbsp;ghc 6.10.1 -O2 -fvia-C &nbsp; &nbsp; &nbsp;: &nbsp;1.966 secs<br>
&gt; &nbsp;C++:<br>
&gt; &nbsp; &nbsp;gcc 3.4.5 -O3 -funroll-loops: &nbsp;0.062 secs<br>
&gt;<br>
</div>Nice! Now we know that gcc can calculate faster than Haskell can<br>
calculate and print. Next time, use exitWith, please.<br>
<font color="#888888"><br>
<br>
--<br>
(c) this sig last receiving data processing entity. Inspect headers<br>
for copyright history. All rights reserved. Copying, hiring, renting,<br>
performance and/or quoting of this signature prohibited.<br>
</font><div><div></div><div class="Wj3C7c"><br>
<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</div></div></blockquote></div><br></div>