<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Use a Better Algorithm and Beat Haskell Today!</title>
	<atom:link href="http://www.jakevoytko.com/blog/2007/11/29/use-a-better-algorithm-and-beat-haskell-today/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jakevoytko.com/blog/2007/11/29/use-a-better-algorithm-and-beat-haskell-today/</link>
	<description>Ye Olde Computer Science Blogge</description>
	<lastBuildDate>Fri, 18 Jun 2010 17:23:52 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: Ungraspiness</title>
		<link>http://www.jakevoytko.com/blog/2007/11/29/use-a-better-algorithm-and-beat-haskell-today/comment-page-1/#comment-1423</link>
		<dc:creator>Ungraspiness</dc:creator>
		<pubDate>Fri, 30 Nov 2007 05:59:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.jakevoytko.com/blog/2007/11/29/use-a-better-algorithm-and-beat-haskell-today/#comment-1423</guid>
		<description>Lisp !

http://jng.imagine27.com/articles/2007/11/29/dude-your-quad-cores-have-been-smoking-way-too-much-haskell</description>
		<content:encoded><![CDATA[<p>Lisp !</p>
<p><a href="http://jng.imagine27.com/articles/2007/11/29/dude-your-quad-cores-have-been-smoking-way-too-much-haskell" rel="nofollow">http://jng.imagine27.com/articles/2007/11/29/dude-your-quad-cores-have-been-smoking-way-too-much-haskell</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jake</title>
		<link>http://www.jakevoytko.com/blog/2007/11/29/use-a-better-algorithm-and-beat-haskell-today/comment-page-1/#comment-1415</link>
		<dc:creator>Jake</dc:creator>
		<pubDate>Fri, 30 Nov 2007 01:38:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.jakevoytko.com/blog/2007/11/29/use-a-better-algorithm-and-beat-haskell-today/#comment-1415</guid>
		<description>@dons:

You didn&#039;t do anything wrong, but I had used the C++ interface instead of the C interface for legibility reasons. (there is some overhead involved)

&lt;pre lang=&quot;cpp&quot;&gt;
  mpz_class fib(unsigned int num)
  {
    mpz_t a, b;

    mpz_init(a);
    mpz_init(b);

    mpz_set_ui(a, 1);
    mpz_set_ui(b, 1);

    while(num-- &gt; 1)
    {
      mpz_swap(a, b);
      mpz_add(a, a, b);
    }
    cout&lt;&lt;mpz_class(a)&lt;&lt;endl;
  }
&lt;/pre&gt;

&lt;pre lang=&quot;cpp&quot;&gt;
Time: 1.85574 seconds
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>@dons:</p>
<p>You didn&#8217;t do anything wrong, but I had used the C++ interface instead of the C interface for legibility reasons. (there is some overhead involved)</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">  mpz_class fib<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span> num<span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    mpz_t a, b<span style="color: #008080;">;</span>
&nbsp;
    mpz_init<span style="color: #008000;">&#40;</span>a<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    mpz_init<span style="color: #008000;">&#40;</span>b<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
    mpz_set_ui<span style="color: #008000;">&#40;</span>a, <span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    mpz_set_ui<span style="color: #008000;">&#40;</span>b, <span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000ff;">while</span><span style="color: #008000;">&#40;</span>num<span style="color: #000040;">--</span> <span style="color: #000080;">&gt;</span> <span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
      mpz_swap<span style="color: #008000;">&#40;</span>a, b<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
      mpz_add<span style="color: #008000;">&#40;</span>a, a, b<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0000dd;">cout</span><span style="color: #000080;">&lt;&lt;</span>mpz_class<span style="color: #008000;">&#40;</span>a<span style="color: #008000;">&#41;</span><span style="color: #000080;">&lt;&lt;</span>endl<span style="color: #008080;">;</span>
  <span style="color: #008000;">&#125;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">Time<span style="color: #008080;">:</span> <span style="color:#800080;">1.85574</span> seconds</pre></div></div>

]]></content:encoded>
	</item>
	<item>
		<title>By: magnus</title>
		<link>http://www.jakevoytko.com/blog/2007/11/29/use-a-better-algorithm-and-beat-haskell-today/comment-page-1/#comment-1414</link>
		<dc:creator>magnus</dc:creator>
		<pubDate>Fri, 30 Nov 2007 01:27:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.jakevoytko.com/blog/2007/11/29/use-a-better-algorithm-and-beat-haskell-today/#comment-1414</guid>
		<description>If I define the equivalent program:

&gt; fibs = 1:1:(zipWith (+) fibs (tail fibs))
&gt;
&gt; main = do let x = fibs !! 200000 in print &quot;done&quot;

and compile it,

% ghc tmp.hs
% time ./a.out
&quot;done&quot;
./a.out  0.00s user 0.00s system 84% cpu 0.003 total

0 seconds!!

anyway if I shove a seq in there to force evaluation I get,
8.73s user 0.04s system 99% cpu 8.773 total</description>
		<content:encoded><![CDATA[<p>If I define the equivalent program:</p>
<p>&gt; fibs = 1:1:(zipWith (+) fibs (tail fibs))<br />
&gt;<br />
&gt; main = do let x = fibs !! 200000 in print &#8220;done&#8221;</p>
<p>and compile it,</p>
<p>% ghc tmp.hs<br />
% time ./a.out<br />
&#8220;done&#8221;<br />
./a.out  0.00s user 0.00s system 84% cpu 0.003 total</p>
<p>0 seconds!!</p>
<p>anyway if I shove a seq in there to force evaluation I get,<br />
8.73s user 0.04s system 99% cpu 8.773 total</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joel Parish</title>
		<link>http://www.jakevoytko.com/blog/2007/11/29/use-a-better-algorithm-and-beat-haskell-today/comment-page-1/#comment-1412</link>
		<dc:creator>Joel Parish</dc:creator>
		<pubDate>Fri, 30 Nov 2007 01:06:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.jakevoytko.com/blog/2007/11/29/use-a-better-algorithm-and-beat-haskell-today/#comment-1412</guid>
		<description>The Parallel haskell post you referenced specifically stated that they were using the *naive* algorithm in order to test ease of parallelization rather than that specific algorithm. Binet&#039;s Formula, the Matrix Multiplication method will yield faster results than iteration for larger n. If you want an apples to apples comparison to your iterative method consider:
&lt;code&gt;
xor ax, ax
push ax
mov ax, 1
push ax
mov cx, 0x24 ; number of loops, in hex

crunch:

pop ax
pop bx
add sp, 4
add ax, bx
push ax
loop crunch

ret
&lt;/code&gt;
from &lt;a href=&quot;http://patrickyeon.blogspot.com/2007/11/holy-cannoli-here-comes-assembly.html&quot; rel=&quot;nofollow&quot;&gt;http://patrickyeon.blogspot.com/2007/11/holy-cannoli-here-comes-assembly.html&lt;/a&gt;</description>
		<content:encoded><![CDATA[<p>The Parallel haskell post you referenced specifically stated that they were using the *naive* algorithm in order to test ease of parallelization rather than that specific algorithm. Binet&#8217;s Formula, the Matrix Multiplication method will yield faster results than iteration for larger n. If you want an apples to apples comparison to your iterative method consider:<br />
<code><br />
xor ax, ax<br />
push ax<br />
mov ax, 1<br />
push ax<br />
mov cx, 0x24 ; number of loops, in hex</p>
<p>crunch:</p>
<p>pop ax<br />
pop bx<br />
add sp, 4<br />
add ax, bx<br />
push ax<br />
loop crunch</p>
<p>ret<br />
</code><br />
from <a href="http://patrickyeon.blogspot.com/2007/11/holy-cannoli-here-comes-assembly.html" rel="nofollow">http://patrickyeon.blogspot.com/2007/11/holy-cannoli-here-comes-assembly.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dons</title>
		<link>http://www.jakevoytko.com/blog/2007/11/29/use-a-better-algorithm-and-beat-haskell-today/comment-page-1/#comment-1410</link>
		<dc:creator>dons</dc:creator>
		<pubDate>Fri, 30 Nov 2007 00:29:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.jakevoytko.com/blog/2007/11/29/use-a-better-algorithm-and-beat-haskell-today/#comment-1410</guid>
		<description>I&#039;ll see your linear C++, and raise you some linear Haskell:


    main = print (fib 200000)

    fib :: Int -&gt; Integer
    fib n = go n 1 1
        where
            go 1 a _ = a
            go n a b = go (n-1) (a + b) a 


On my machine, your code:


   $ g++ fib.cpp -O2 -lgmp -lgmpxx -o fib
   $ time ./fib
   Fibonacci test for Fib(200000)
   Time: 1.34055 seconds
   ./fib  1.32s user 0.02s system 98% cpu 1.360 total


And the Haskell translation:


    $ ghc-6.8.1 -O2 -optc-O2 A.hs -o A
    $ time ./A
2440914874035154859992549871532124086962886075690...
    ...622248628614359062
    ./A  0.48s user 0.01s system 98% cpu 0.504 total


Maybe you need more cores! (Or did I do something wrong?)</description>
		<content:encoded><![CDATA[<p>I&#8217;ll see your linear C++, and raise you some linear Haskell:</p>
<p>    main = print (fib 200000)</p>
<p>    fib :: Int -&gt; Integer<br />
    fib n = go n 1 1<br />
        where<br />
            go 1 a _ = a<br />
            go n a b = go (n-1) (a + b) a </p>
<p>On my machine, your code:</p>
<p>   $ g++ fib.cpp -O2 -lgmp -lgmpxx -o fib<br />
   $ time ./fib<br />
   Fibonacci test for Fib(200000)<br />
   Time: 1.34055 seconds<br />
   ./fib  1.32s user 0.02s system 98% cpu 1.360 total</p>
<p>And the Haskell translation:</p>
<p>    $ ghc-6.8.1 -O2 -optc-O2 A.hs -o A<br />
    $ time ./A<br />
2440914874035154859992549871532124086962886075690&#8230;<br />
    &#8230;622248628614359062<br />
    ./A  0.48s user 0.01s system 98% cpu 0.504 total</p>
<p>Maybe you need more cores! (Or did I do something wrong?)</p>
]]></content:encoded>
	</item>
</channel>
</rss>
