[Haskell-cafe] benchmarking c/c++ and haskell
Vo Minh Thu
noteed at gmail.com
Sun Sep 12 07:39:57 EDT 2010
2010/9/12 Andrew Coppin <andrewcoppin at btinternet.com>:
> Vo Minh Thu wrote:
>>
>> Hi,
>>
>> I would like to benchmark C/C++ and Haskell code. The goal is to
>> improve the Haskell port[0] of smallpt[1].
>>
>> To make sure my approach was reliable, I got the code of two programs
>> (one in C, the other in Haskell) from a post[2] by Don. The code is
>> reproduced below. When timing the execution of both program, I have a
>>
>>>
>>> 4x difference. It is said on the blog the programs should have
>>>
>>
>> similar performance.
>>
>> I simply don't get the reason of such a difference. I've tried the
>> code on my Atom netbook and also on an older centrino machine. The
>> timing are similar (i.e. the C and Haskell program show >4x
>> difference). Both machines have GHC 6.12.1 on Linux.
>>
>> Would you have an idea?
>>
>
> The function floor :: Double -> Int is surprisingly slow under GHC. (IIRC,
> it's implemented by converting Double -> (Int, Integer) -> Int, or something
> equally absurd.) Poking around GHC.Prim directly allows you to do the same
> operation much, much faster. I couldn't say exactly how much of a difference
> it makes, but I've had programs go from seconds to microseconds just by
> switching this.
>
> http://hackage.haskell.org/trac/ghc/ticket/2271
> http://hackage.haskell.org/trac/ghc/ticket/1434
>
> My solution was to do this:
>
> http://hackage.haskell.org/packages/archive/AC-Colour/1.1.3/doc/html/src/Data-Colour-FastFloor.html
>
> Uh... good luck! o_O
Thanks for the tip. But I would really get the two little programs
from Don's blog to have the same performance as advertised so that I
can build from there. I have to make sure things are different for a
good reason, not because of a flaw in my setup (which I assume it is
since I can't even get those two to run in the same time).
Thanks,
Thu
More information about the Haskell-Cafe
mailing list