<?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: The battle of the languages part II</title>
	<atom:link href="http://tempe.st/2007/05/the-battle-of-the-languages-part-ii/feed/" rel="self" type="application/rss+xml" />
	<link>http://tempe.st/2007/05/the-battle-of-the-languages-part-ii/</link>
	<description>aka blog.to_int(:inig)</description>
	<lastBuildDate>Mon, 08 Feb 2010 13:08:27 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: Jaroslaw Zabiello</title>
		<link>http://tempe.st/2007/05/the-battle-of-the-languages-part-ii/comment-page-1/#comment-2234</link>
		<dc:creator>Jaroslaw Zabiello</dc:creator>
		<pubDate>Mon, 12 Jan 2009 15:35:17 +0000</pubDate>
		<guid isPermaLink="false">http://tempe.st/2007/05/the-battle-of-the-languages-part-ii/#comment-2234</guid>
		<description>I have slighty different results:

Lua 5.1.4: 2.95s  
JRuby 1.1.7 (trunk) --fast --server: 4.93s
Python 2.6.1: 7.92s 
PHP 5.2.8: 8.20s
Ruby EE 1.8.6: 10.08s

platform: Mac OS-X 10.5.6, PowerMac 2x2.8GHz</description>
		<content:encoded><![CDATA[<p>I have slighty different results:</p>
<p>Lua 5.1.4: 2.95s  <br />
JRuby 1.1.7 (trunk)&#8212;fast&#8212;server: 4.93s<br />
Python 2.6.1: 7.92s <br />
PHP 5.2.8: 8.20s<br />
Ruby EE 1.8.6: 10.08s</p>
<p>platform: Mac OS-X 10.5.6, PowerMac 2&#215;2.8GHz</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jaroslaw Zabiello</title>
		<link>http://tempe.st/2007/05/the-battle-of-the-languages-part-ii/comment-page-1/#comment-2233</link>
		<dc:creator>Jaroslaw Zabiello</dc:creator>
		<pubDate>Mon, 12 Jan 2009 14:37:33 +0000</pubDate>
		<guid isPermaLink="false">http://tempe.st/2007/05/the-battle-of-the-languages-part-ii/#comment-2233</guid>
		<description>It all depends what you test... Why not add JRuby and RUby 1.9? They kill PHP. http://gist.github.com/42915. For web frameworks see: http://www.slideshare.net/mattetti/merb-presentation-at-orug-presentation</description>
		<content:encoded><![CDATA[<p>It all depends what you test&#8230; Why not add JRuby and RUby 1.9? They kill PHP. <a href="http://gist.github.com/42915" rel="nofollow">http://gist.github.com/42915</a>. For web frameworks see: <a href="http://www.slideshare.net/mattetti/merb-presentation-at-orug-presentation" rel="nofollow">http://www.slideshare.net/mattetti/merb-presentation-at-orug-presentation</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex</title>
		<link>http://tempe.st/2007/05/the-battle-of-the-languages-part-ii/comment-page-1/#comment-369</link>
		<dc:creator>Alex</dc:creator>
		<pubDate>Wed, 28 Nov 2007 07:05:51 +0000</pubDate>
		<guid isPermaLink="false">http://tempe.st/2007/05/the-battle-of-the-languages-part-ii/#comment-369</guid>
		<description>Python:

from time import clock

start = clock()
from math import sqrt

results = [(sqrt(c*c - b*b),b,c) for c in xrange(2,5001) for b in xrange(1,c)  if sqrt(c*c - b*b) %1 == 0.0]

print clock() - start

And if I wanted to cheat and beat everything, including Fortran, in the speed department:

from time import clock

start = clock()
from math import sqrt

results = ((sqrt(c*c - b*b),b,c) for c in xrange(2,5001) for b in xrange(1,c)  if sqrt(c*c - b*b) %1 == 0.0)

print clock() - start

:P</description>
		<content:encoded><![CDATA[<p>Python:</p>
<p>from time import clock</p>
<p>start = clock()<br />
from math import sqrt</p>
<p>results = [(sqrt(c*c &#8211; b*b),b,c) for c in xrange(2,5001) for b in xrange(1,c)  if sqrt(c*c &#8211; b*b) %1  0.0]</p>
<p>print clock() &#45; start</p>
<p>And if I wanted to cheat and beat everything, including Fortran, in the speed department:</p>
<p>from time import clock</p>
<p>start &#61; clock()<br />
from math import sqrt</p>
<p>results &#61; ((sqrt(c&#42;c &#45; b&#42;b),b,c) for c in xrange(2,5001) for b in xrange(1,c)  if sqrt(c&#42;c &#45; b&#42;b) &#37;1  0.0)</p>
<p>print clock() &#8211; start</p>
<p> <img src='http://tempe.st/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dmitrii 'Mamut' Dimandt</title>
		<link>http://tempe.st/2007/05/the-battle-of-the-languages-part-ii/comment-page-1/#comment-237</link>
		<dc:creator>Dmitrii 'Mamut' Dimandt</dc:creator>
		<pubDate>Wed, 06 Jun 2007 11:28:14 +0000</pubDate>
		<guid isPermaLink="false">http://tempe.st/2007/05/the-battle-of-the-languages-part-ii/#comment-237</guid>
		<description>I wonder if my previous comment has been lost...

This is going to be rather longish and slightly offtopic...

Here&#039;s some code from a Russian site, http://rsdn.ru/forum/message/2515740.1.aspx (you may llok there to see pretty printed code):

Original author is not me :)

[start quote]
Haskell&#039;s GHC compiler is pretty bad when it comes to double-precision floating point arythmetic (or maybe I&#039;m doing something wrong)

If we directly rewrite the test:

pythags :: Double -&gt; Int
pythags mp = pyth 2 0
  where
    pyth c i &#124; c &gt; mp    = i
             &#124; otherwise = pyth (c+1) (i + (pyth&#039; 1 0))
      where
        pyth&#039; b j &#124; b == c    = j
                  &#124; otherwise = let a = sqrt (c*c - b*b)
                                in  if  a == fromIntegral ((truncate a)::Int)
                                        then pyth&#039; (b+1) (j+1)
                                        else pyth&#039; (b+1)   j


or like this:


pythags :: Double -&gt; Int
pythags mp = length [ () &#124; c 

then it will be approx. 40 times slower than VisualC or 25 times slower than GCC:


int pyphags(double mp) 
{
    double c, b;
    int i = 0;
    double a;

    for (c = 2; c 

If we, however, rewrite the test using integers only:

pythags :: Int -&gt; Int
pythags mp = length [ () &#124; c 

then the difference between GHC and GCC will be less than that between VisualC and GCC:


int pyphags(int mp) 
{
    int a, b, c, s, i=0;

    for (c = 2; c 

When mp = 5000 my computer gives: 

                  Double        Int
VisualC   8.0     0.9 sec     0.7 sec
GCC mingw 3.4.5   1.4 sec     1.0 sec
GHC       6.6    34   sec     1.3 sec


Note. GCC 6.2 that comes with GHC 6.6 (Win32) has a slow implementation of sqrt in math.h, so I defined fastDoubleSqrt and fastIntSqrt for GCC as follows:


__inline double fastDoubleSqrt(double x) 
{
  register double res;
  __asm __volatile__ (&quot;fsqrt&quot; : &quot;=t&quot; (res) : &quot;0&quot; (x));
  return res;
}

__inline int fastIntSqrt(int x)
{
    return (int)fastDoubleSqrt((double)x);
}


For VisualC (it&#039;s ok in this department):

inline double fastDoubleSqrt(double x) 
{
  return sqrt(x);
}

inline int fastIntSqrt(double x) 
{
    return ((int)sqrt((double)x);
}


[end quote]</description>
		<content:encoded><![CDATA[<p>I wonder if my previous comment has been lost&#8230;</p>
<p>This is going to be rather longish and slightly offtopic&#8230;</p>
<p>Here&#8217;s some code from a Russian site, <a href="http://rsdn.ru/forum/message/2515740.1.aspx" rel="nofollow">http://rsdn.ru/forum/message/2515740.1.aspx</a> (you may llok there to see pretty printed code):</p>
<p>Original author is not me <img src='http://tempe.st/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>[start quote]<br />
Haskell&#8217;s GHC compiler is pretty bad when it comes to double-precision floating point arythmetic (or maybe I&#8217;m doing something wrong)</p>
<p>If we directly rewrite the test:</p>
<p>pythags :: Double -> Int<br />
pythags mp = pyth 2 0<br />
  where<br />
    pyth c i | c > mp    = i<br />
             | otherwise = pyth (c+1) (i + (pyth&#8217; 1 0))<br />
      where<br />
        pyth&#8217; b j | b  c    &#61; j<br />
                  | otherwise &#61; let a &#61; sqrt (c&#42;c &#45; b&#42;b)<br />
                                in  if  a  fromIntegral ((truncate a)::Int)<br />
                                        then pyth&#8217; (b+1) (j+1)<br />
                                        else pyth&#8217; (b+1)   j</p>
<p>or like this:</p>
<p>pythags :: Double -> Int<br />
pythags mp = length [ () | c </p>
<p>then it will be approx. 40 times slower than VisualC or 25 times slower than GCC:</p>
<p>int pyphags(double mp) <br />
{<br />
    double c, b;<br />
    int i = 0;<br />
    double a;</p>
<p>    for (c = 2; c </p>
<p>If we, however, rewrite the test using integers only:</p>
<p>pythags :: Int -> Int<br />
pythags mp = length [ () | c </p>
<p>then the difference between GHC and GCC will be less than that between VisualC and GCC:</p>
<p>int pyphags(int mp) <br />
{<br />
    int a, b, c, s, i=0;</p>
<p>    for (c = 2; c </p>
<p>When mp = 5000 my computer gives: </p>
<p>                  Double        Int<br />
VisualC   8.0     0.9 sec     0.7 sec<br />
GCC mingw 3.4.5   1.4 sec     1.0 sec<br />
GHC       6.6    34   sec     1.3 sec</p>
<p>Note. GCC 6.2 that comes with GHC 6.6 (Win32) has a slow implementation of sqrt in math.h, so I defined fastDoubleSqrt and fastIntSqrt for GCC as follows:</p>
<p>__inline double fastDoubleSqrt(double x) <br />
{<br />
  register double res;<br />
  __asm <i>volatile</i> (&#8220;fsqrt&#8221; : &#8221;=t&#8221; (res) : &#8220;0&#8221; (x));<br />
  return res;<br />
}</p>
<p>__inline int fastIntSqrt(int x)<br />
{<br />
    return (int)fastDoubleSqrt((double)x);<br />
}</p>
<p>For VisualC (it&#8217;s ok in this department):</p>
<p>inline double fastDoubleSqrt(double x) <br />
{<br />
  return sqrt(x);<br />
}</p>
<p>inline int fastIntSqrt(double x) <br />
{<br />
    return ((int)sqrt((double)x);<br />
}</p>
<p>[end quote]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dmitrii 'Mamut' Dimandt</title>
		<link>http://tempe.st/2007/05/the-battle-of-the-languages-part-ii/comment-page-1/#comment-236</link>
		<dc:creator>Dmitrii 'Mamut' Dimandt</dc:creator>
		<pubDate>Wed, 06 Jun 2007 11:26:51 +0000</pubDate>
		<guid isPermaLink="false">http://tempe.st/2007/05/the-battle-of-the-languages-part-ii/#comment-236</guid>
		<description>This is going to be rather longish and slightly offtopic...

Here&#039;s some code from a Russian site, http://rsdn.ru/forum/message/2515740.1.aspx (you may llok there to see pretty printed code):

Original author is not me :)

[start quote]
Haskell&#039;s GHC compiler is pretty bad when it comes to double-precision floating point arythmetic (or maybe I&#039;m doing something wrong)

If we directly rewrite the test:

pythags :: Double -&gt; Int
pythags mp = pyth 2 0
  where
    pyth c i &#124; c &gt; mp    = i
             &#124; otherwise = pyth (c+1) (i + (pyth&#039; 1 0))
      where
        pyth&#039; b j &#124; b == c    = j
                  &#124; otherwise = let a = sqrt (c*c - b*b)
                                in  if  a == fromIntegral ((truncate a)::Int)
                                        then pyth&#039; (b+1) (j+1)
                                        else pyth&#039; (b+1)   j


or like this:


pythags :: Double -&gt; Int
pythags mp = length [ () &#124; c 

then it will be approx. 40 times slower than VisualC or 25 times slower than GCC:


int pyphags(double mp) 
{
    double c, b;
    int i = 0;
    double a;

    for (c = 2; c 

If we, however, rewrite the test using integers only:

pythags :: Int -&gt; Int
pythags mp = length [ () &#124; c 

then the difference between GHC and GCC will be less than that between VisualC and GCC:


int pyphags(int mp) 
{
    int a, b, c, s, i=0;

    for (c = 2; c 

When mp = 5000 my computer gives: 

                  Double        Int
VisualC   8.0     0.9 sec     0.7 sec
GCC mingw 3.4.5   1.4 sec     1.0 sec
GHC       6.6    34   sec     1.3 sec


Note. GCC 6.2 that comes with GHC 6.6 (Win32) has a slow implementation of sqrt in math.h, so I defined fastDoubleSqrt and fastIntSqrt for GCC as follows:


__inline double fastDoubleSqrt(double x) 
{
  register double res;
  __asm __volatile__ (&quot;fsqrt&quot; : &quot;=t&quot; (res) : &quot;0&quot; (x));
  return res;
}

__inline int fastIntSqrt(int x)
{
    return (int)fastDoubleSqrt((double)x);
}


For VisualC (it&#039;s ok in this department):

inline double fastDoubleSqrt(double x) 
{
  return sqrt(x);
}

inline int fastIntSqrt(double x) 
{
    return ((int)sqrt((double)x);
}


[end quote]</description>
		<content:encoded><![CDATA[<p>This is going to be rather longish and slightly offtopic&#8230;</p>
<p>Here&#8217;s some code from a Russian site, <a href="http://rsdn.ru/forum/message/2515740.1.aspx" rel="nofollow">http://rsdn.ru/forum/message/2515740.1.aspx</a> (you may llok there to see pretty printed code):</p>
<p>Original author is not me <img src='http://tempe.st/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>[start quote]<br />
Haskell&#8217;s GHC compiler is pretty bad when it comes to double-precision floating point arythmetic (or maybe I&#8217;m doing something wrong)</p>
<p>If we directly rewrite the test:</p>
<p>pythags :: Double -> Int<br />
pythags mp = pyth 2 0<br />
  where<br />
    pyth c i | c > mp    = i<br />
             | otherwise = pyth (c+1) (i + (pyth&#8217; 1 0))<br />
      where<br />
        pyth&#8217; b j | b  c    &#61; j<br />
                  | otherwise &#61; let a &#61; sqrt (c&#42;c &#45; b&#42;b)<br />
                                in  if  a  fromIntegral ((truncate a)::Int)<br />
                                        then pyth&#8217; (b+1) (j+1)<br />
                                        else pyth&#8217; (b+1)   j</p>
<p>or like this:</p>
<p>pythags :: Double -> Int<br />
pythags mp = length [ () | c </p>
<p>then it will be approx. 40 times slower than VisualC or 25 times slower than GCC:</p>
<p>int pyphags(double mp) <br />
{<br />
    double c, b;<br />
    int i = 0;<br />
    double a;</p>
<p>    for (c = 2; c </p>
<p>If we, however, rewrite the test using integers only:</p>
<p>pythags :: Int -> Int<br />
pythags mp = length [ () | c </p>
<p>then the difference between GHC and GCC will be less than that between VisualC and GCC:</p>
<p>int pyphags(int mp) <br />
{<br />
    int a, b, c, s, i=0;</p>
<p>    for (c = 2; c </p>
<p>When mp = 5000 my computer gives: </p>
<p>                  Double        Int<br />
VisualC   8.0     0.9 sec     0.7 sec<br />
GCC mingw 3.4.5   1.4 sec     1.0 sec<br />
GHC       6.6    34   sec     1.3 sec</p>
<p>Note. GCC 6.2 that comes with GHC 6.6 (Win32) has a slow implementation of sqrt in math.h, so I defined fastDoubleSqrt and fastIntSqrt for GCC as follows:</p>
<p>__inline double fastDoubleSqrt(double x) <br />
{<br />
  register double res;<br />
  __asm <i>volatile</i> (&#8220;fsqrt&#8221; : &#8221;=t&#8221; (res) : &#8220;0&#8221; (x));<br />
  return res;<br />
}</p>
<p>__inline int fastIntSqrt(int x)<br />
{<br />
    return (int)fastDoubleSqrt((double)x);<br />
}</p>
<p>For VisualC (it&#8217;s ok in this department):</p>
<p>inline double fastDoubleSqrt(double x) <br />
{<br />
  return sqrt(x);<br />
}</p>
<p>inline int fastIntSqrt(double x) <br />
{<br />
    return ((int)sqrt((double)x);<br />
}</p>
<p>[end quote]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stuart Dootson</title>
		<link>http://tempe.st/2007/05/the-battle-of-the-languages-part-ii/comment-page-1/#comment-234</link>
		<dc:creator>Stuart Dootson</dc:creator>
		<pubDate>Wed, 06 Jun 2007 05:08:22 +0000</pubDate>
		<guid isPermaLink="false">http://tempe.st/2007/05/the-battle-of-the-languages-part-ii/#comment-234</guid>
		<description>Bah - I put it in &lt;pre&gt; tags and it&#039;s still lost the indentation.

OK - the line starting &#039;where a =&#039; should be indented (by a tab-stop, or the equivalent in spaces), and the next line I have indented so that the start of &#039;diff =&#039; lines up with the start of &#039;a =&#039;.</description>
		<content:encoded><![CDATA[<p>Bah &#8211; I put it in
<pre> tags and it's still lost the indentation.</pre>
</p>
<p>OK - the line starting 'where a =' should be indented (by a tab-stop, or the equivalent in spaces), and the next line I have indented so that the start of 'diff =' lines up with the start of 'a ='.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stuart Dootson</title>
		<link>http://tempe.st/2007/05/the-battle-of-the-languages-part-ii/comment-page-1/#comment-233</link>
		<dc:creator>Stuart Dootson</dc:creator>
		<pubDate>Wed, 06 Jun 2007 05:05:03 +0000</pubDate>
		<guid isPermaLink="false">http://tempe.st/2007/05/the-battle-of-the-languages-part-ii/#comment-233</guid>
		<description>Giovanni - I&#039;ve just realised that the displayed Haskell code in my comment(s) has lost all indentation. Haskell is a little like Python, in that indentation can be significant. Hopefully, this repost won&#039;t lost the indentation (I&#039;m not 100% sure about what I can and can&#039;t post in the comments re: HTML tags...)

&lt;pre&gt;
module Main where

isPythag :: Int -&gt; Int -&gt; Bool
isPythag c b = 
   (a*a)==diff
   where a = ratSqrt (diff)
         diff = (c*c)-(b*b)

ratSqrt :: Int -&gt; Int
ratSqrt = truncate.sqrt.fromIntegral

main = (putStrLn.show.length) [ 1 &#124; c&lt;-[2..5000],b&lt;-[1..c-1], isPythag c b ]
</description>
		<content:encoded><![CDATA[<p>Giovanni &#8211; I&#8217;ve just realised that the displayed Haskell code in my comment(s) has lost all indentation. Haskell is a little like Python, in that indentation can be significant. Hopefully, this repost won&#8217;t lost the indentation (I&#8217;m not 100% sure about what I can and can&#8217;t post in the comments re: HTML tags&#8230;)</p>
<pre>
module Main where

isPythag :: Int -&gt; Int &lt;del&gt;&gt; Bool
isPythag c b =
   (a*a)==diff
   where a = ratSqrt (diff)
         diff = (c*c)&lt;/del&gt;(b*b)

ratSqrt :: Int &lt;del&gt;&gt; Int
ratSqrt = truncate.sqrt.fromIntegral

main = (putStrLn.show.length) [ 1 | c&lt;&lt;/del&gt;[2..5000],b&lt;-[1..c-1], isPythag c b ]
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Giovanni Intini</title>
		<link>http://tempe.st/2007/05/the-battle-of-the-languages-part-ii/comment-page-1/#comment-232</link>
		<dc:creator>Giovanni Intini</dc:creator>
		<pubDate>Mon, 04 Jun 2007 10:07:23 +0000</pubDate>
		<guid isPermaLink="false">http://tempe.st/2007/05/the-battle-of-the-languages-part-ii/#comment-232</guid>
		<description>I&#039;m going to install ghc right now :)</description>
		<content:encoded><![CDATA[<p>I&#8217;m going to install ghc right now <img src='http://tempe.st/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stuart Dootson</title>
		<link>http://tempe.st/2007/05/the-battle-of-the-languages-part-ii/comment-page-1/#comment-231</link>
		<dc:creator>Stuart Dootson</dc:creator>
		<pubDate>Sat, 02 Jun 2007 14:13:01 +0000</pubDate>
		<guid isPermaLink="false">http://tempe.st/2007/05/the-battle-of-the-languages-part-ii/#comment-231</guid>
		<description>Final comment - compilation tips:

Put the code into a file called a.hs and compile with &#039;ghc -O2 a.hs -o a&#039;</description>
		<content:encoded><![CDATA[<p>Final comment &#8211; compilation tips:</p>
<p>Put the code into a file called a.hs and compile with &#8216;ghc -O2 a.hs -o a&#8217;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stuart Dootson</title>
		<link>http://tempe.st/2007/05/the-battle-of-the-languages-part-ii/comment-page-1/#comment-230</link>
		<dc:creator>Stuart Dootson</dc:creator>
		<pubDate>Sat, 02 Jun 2007 14:11:42 +0000</pubDate>
		<guid isPermaLink="false">http://tempe.st/2007/05/the-battle-of-the-languages-part-ii/#comment-230</guid>
		<description>Sorry - it was the less-then sign - here&#039;s my &#039;main&#039;...

main = (putStrLn.show.length) [ 1 &#124; c&lt;-[2..5000],b&lt;-[1..c-1], isPythag c b ]</description>
		<content:encoded><![CDATA[<p>Sorry &#8211; it was the less-then sign &#8211; here&#8217;s my &#8216;main&#8217;...</p>
<p>main = (putStrLn.show.length) [ 1 | c< -[2..5000],b<-[1..c-1], isPythag c b ]</p></p>
]]></content:encoded>
	</item>
</channel>
</rss>
