[Haskell-cafe] Can Haskell outperform C++?

Ertugrul Söylemez es at ertes.de
Sun May 6 13:52:47 CEST 2012


Roman Cheplyaka <roma at ro-che.info> wrote:

> >  isn't it that particular Haskell code is outperforming C (22
> > seconds vs. 33), just because the author uses recursion in C? I
> > surely love Haskell, and the way it's code is easy parallelized, but
> > that example seams not fair.
>
> I think the point was to take two programs of similar code complexity
> (or, rather, simplicity) implementing the same algorithm (modulo
> parallelism).
>
> So I'm not sure what exactly you're objecting to.

I think while this is a valid argument it is not very convincing.  You
have to acknowledge that C and C++ can give better performance at number
crunching.  The gain is small enough that personally I wouldn't go
through the trouble of writing my algorithms in C/C++, but simple-minded
people often have a desire to get the best performance possible, in
which case you really want to use C, C++, Fortran or whatever high level
assembler language you like.

In other words:  Writing Haskell in C is just as wrong as writing C in
Haskell.  A comparison of algorithm /implementation styles/ does not
have much semantic content.  It just shows that Haskell rocks at high
level optimization while C rocks at low level optimization.  By the same
experiment you can see that Haskell is bad at low level optimization
while C is bad at high level optimization.

In order to compare code performance you have to implement the same
algorithm in the idiomatic style in both languages.  This experiment
would show that Haskell, even though it gets close, is still slower than
C.  It would however show that interpreted Python and Ruby are
considerably slower than both.


Greets,
Ertugrul

-- 
nightmare = unsafePerformIO (getWrongWife >>= sex)
http://ertes.de/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120506/78986d4c/attachment.pgp>


More information about the Haskell-Cafe mailing list