<div dir="ltr"><div>At the risk of getting sucked into a silly discussion, I&#39;d like to point out that the c code uses the following &quot;really simple and naive&quot; function:</div><div><br class="webkit-block-placeholder">
</div><div><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"><a href="http://sourceware.org/cgi-bin/cvsweb.cgi/libc/stdlib/strtol.c?rev=1.42.2.2&amp;content-type=text/x-cvsweb-markup&amp;cvsroot=glibc">http://sourceware.org/cgi-bin/cvsweb.cgi/libc/stdlib/strtol.c?rev=1.42.2.2&amp;content-type=text/x-cvsweb-markup&amp;cvsroot=glibc</a></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"><br class="webkit-block-placeholder"></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"><a href="http://sourceware.org/cgi-bin/cvsweb.cgi/libc/stdlib/strtol_l.c?rev=1.4.2.3&amp;content-type=text/x-cvsweb-markup&amp;cvsroot=glibc">http://sourceware.org/cgi-bin/cvsweb.cgi/libc/stdlib/strtol_l.c?rev=1.4.2.3&amp;content-type=text/x-cvsweb-markup&amp;cvsroot=glibc</a></p>
</div><div><br class="webkit-block-placeholder"></div><div>Oh, and it &quot;simply and naively&quot; loops with the following:</div><div><span class="Apple-style-span" style="font-family: verdana; "><pre style="margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-bottom: 1em; white-space: pre; font-size: small; ">
    <span class="hl kwa" style="color: rgb(127, 0, 85); font-weight: bold; ">while</span> <span class="hl sym" style="color: rgb(0, 0, 0); ">(</span><span class="hl kwd">fgets_unlocked</span> <span class="hl sym" style="color: rgb(0, 0, 0); ">(</span>line<span class="hl sym" style="color: rgb(0, 0, 0); ">,</span> MAXLINELEN<span class="hl sym" style="color: rgb(0, 0, 0); ">,</span> stdin<span class="hl sym" style="color: rgb(0, 0, 0); ">))</span>
</pre><div><span class="Apple-style-span" style="font-family: Courier; font-size: 12px; white-space: pre;">If Bulat&#39;s point is that the shootout has inspired work on Haskell performance, and in the stdlibs no less, then lovely, and that&#39;s all to the good. Below every high level interface is lots of low level pain.</span></div>
<div><span class="Apple-style-span" style="font-family: Courier; font-size: 12px; white-space: pre;"><br class="webkit-block-placeholder"></span></div><div><span class="Apple-style-span" style="font-family: Courier; font-size: 12px; white-space: pre;">If his point is anything else, this is getting absurd.</span></div>
<div><span class="Apple-style-span" style="font-family: Courier; font-size: 12px; white-space: pre;"><br class="webkit-block-placeholder"></span></div><div><span class="Apple-style-span" style="font-family: Courier; font-size: 12px; white-space: pre;">--S</span></div>
</span></div><br><div class="gmail_quote">On Mon, Sep 22, 2008 at 8:16 PM, Bulat Ziganshin <span dir="ltr">&lt;<a href="mailto:bulat.ziganshin@gmail.com">bulat.ziganshin@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hello Don,<br>
<div class="Ih2E3d"><br>
Tuesday, September 23, 2008, 3:12:37 AM, you wrote:<br>
<br>
&gt;&gt; for the same reason i don&#39;t feed 5000 men with 7 breads - it&#39;s not my<br>
&gt;&gt; business ;)<br>
<br>
&gt; Ok. So I&#39;ll just say: high level, efficient code is an overriding theme<br>
&gt; of many individuals working on Haskell. Things are better and better<br>
&gt; each year. We do not stand still.<br>
<br>
</div>yes. when we say that things are greatly improving each year, this<br>
means that they was bad previously ;)<br>
<div class="Ih2E3d"><br>
&gt; For example, Bulat cites a paper talking about naive list code from<br>
&gt; 2002, however, by 2008 we know how to do fusion on lists, so it runs in<br>
&gt; the same time as low level loops, the technique is implemented and you<br>
&gt; can download it from hackage,<br>
<br>
&gt; <a href="http://hackage.haskell.org/cgi-bin/hackage-scripts/package/stream-fusion" target="_blank">http://hackage.haskell.org/cgi-bin/hackage-scripts/package/stream-fusion</a><br>
<br>
</div>someone can ask why this great code isn&#39;t used in ghc by default.<br>
probably it is just work in progress which isn&#39;t yet ready to replace<br>
old slow code. then we can see tha fusion isn&#39;t magic wand which<br>
improves speed of every haskell code that&#39;s slower than C one. it just<br>
makes C-speed code sometimes<br>
<div class="Ih2E3d"><br>
&gt; Simon Marlow is busy adding more efficient GC and parallelism to GHC,<br>
&gt; and there&#39;s a summer project to rewrite the native code generator.<br>
<br>
</div>well, i&#39;m sais about *current* real situation. if you consider this as<br>
attack against Haskell developers, it&#39;s your mistake. the problem is<br>
that i many years wrote about slowness of ghc code, every time you<br>
cosider this as attack and write that in future Haskell will become<br>
much faster. we still wait for this future, however<br>
<div class="Ih2E3d"><br>
&gt; GHC gained pointer tagging in the last release cycle, dramatically<br>
&gt; reducing the cost of algebraic data types.<br>
<br>
</div>10-20% speed improvement, on average. it&#39;s the only real improvement<br>
(for my own program) i know. i think that ByteString-related libs<br>
gived more improvements but their use isn&#39;t automatic and they doesn&#39;t<br>
help in any situation. they just provide fast library code for solving<br>
some concrete (although very frequent) situations, such as counting<br>
lines<br>
<div class="Ih2E3d"><br>
&gt; At the same time, we&#39;re writing books about how to program &quot;naively&quot; in<br>
&gt; Haskell, such that your code doesn&#39;t suck. That is: training. Teaching<br>
&gt; people how to write Haskell.<br>
<br>
</div>it is what i say - if naive code was effective and automagically<br>
optimized by ghc, we don&#39;t need all those tutorials. anyone looked<br>
into your tutorial on writing efficient Haskell code, will never say<br>
that it&#39;s easier than in C. so we can conclude that optimized haskell<br>
programs are several times slower than C ones and need several times<br>
more to write<br>
<div class="Ih2E3d"><br>
&gt; We can see it paying off, where naive code performs very very well,<br>
<br>
&gt; <a href="http://shootout.alioth.debian.org/gp4/benchmark.php?test=sumcol&amp;lang=all" target="_blank">http://shootout.alioth.debian.org/gp4/benchmark.php?test=sumcol&amp;lang=all</a><br>
<br>
</div>yes! it&#39;s my beloved example of &quot;elegant&quot; haskell code entirely based<br>
on the readInt function added to ghc libs specifically to win in this<br>
test. it&#39;s implementation is really simple and naive:<br>
<br>
-- ---------------------------------------------------------------------<br>
-- Reading from ByteStrings<br>
<br>
-- | readInt reads an Int from the beginning of the ByteString. &nbsp;If there is no<br>
-- integer at the beginning of the string, it returns Nothing, otherwise<br>
-- it just returns the int read, and the rest of the string.<br>
readInt :: ByteString -&gt; Maybe (Int, ByteString)<br>
readInt as<br>
 &nbsp; &nbsp;| null as &nbsp; = Nothing<br>
 &nbsp; &nbsp;| otherwise =<br>
 &nbsp; &nbsp; &nbsp; &nbsp;case unsafeHead as of<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#39;-&#39; -&gt; loop True &nbsp;0 0 (unsafeTail as)<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#39;+&#39; -&gt; loop False 0 0 (unsafeTail as)<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_ &nbsp; -&gt; loop False 0 0 as<br>
<br>
 &nbsp; &nbsp;where loop :: Bool -&gt; Int -&gt; Int -&gt; ByteString -&gt; Maybe (Int, ByteString)<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;STRICT4(loop)<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;loop neg i n ps<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| null ps &nbsp; = end neg i n ps<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| otherwise =<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case B.unsafeHead ps of<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;w | w &gt;= 0x30<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &amp;&amp; w &lt;= 0x39 -&gt; loop neg (i+1)<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(n * 10 + (fromIntegral w - 0x30))<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(unsafeTail ps)<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| otherwise -&gt; end neg i n ps<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end _ &nbsp; &nbsp;0 _ _ &nbsp;= Nothing<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end True _ n ps = Just (negate n, ps)<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end _ &nbsp; &nbsp;_ n ps = Just (n, ps)<br>
<br>
<br>
<br>
when gcc developers will start to add to C libraries functions<br>
performing shootout benchmarks we will continue this discussion :D<br>
<div class="Ih2E3d"><br>
&gt; And lots and lots more people able to write good code for Hackage.<br>
<br>
&gt; I find Bulat&#39;s outlook rather bleak, and I think it is time to update<br>
&gt; expectations.<br>
<br>
&gt; Progress is beautiful.<br>
<br>
</div><div class="Ih2E3d">:)<br>
<br>
--<br>
Best regards,<br>
&nbsp;Bulat &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;mailto:<a href="mailto:Bulat.Ziganshin@gmail.com">Bulat.Ziganshin@gmail.com</a><br>
<br>
_______________________________________________<br>
</div><div><div></div><div class="Wj3C7c">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>