[Haskell-cafe] Haskell Speed Myth
Thomas Davie
tom.davie at gmail.com
Sat Aug 23 06:36:49 EDT 2008
Lo guys,
I thought you'd like to know about this result. I've been playing
with the debian language shootout programs under OS X, looking at how
fast Haskell code is compared to C on OS X, rather than linux.
Interestingly, Haskell comes out rather better on OS X than it did on
Linux. Here's my results (times in seconds):
C Haskell Relative speed Inverse
Binary Trees 6.842 1.228 0.179479684302835 5.57166123778502
Fannkuch 5.683 15.73 2.76790427591061 0.361284170375079
Mandelbrot 1.183 2.287 1.93322062552832 0.517271534761697
nbody 10.275 16.219 1.57849148418491 0.633516246377705
nsieve 0.167 0.253 1.51497005988024 0.660079051383399
nsieve-bits 0.471 0.713 1.51380042462845 0.660589060308555
partial sums 1.047 1.313 1.25405921680993 0.797410510281797
pidigits 1.238 1.4 1.13085621970921 0.884285714285714
recursive 1.554 3.594 2.31274131274131 0.432387312186978
spectral-norm 27.939 19.165 0.685958695729983 1.45781372293243
threadring 91.284 1.389 0.0152162481924543 65.719222462203
-------------------------------------------------------------------------
Averages 1.35333620432893 0.738914688605306
Some notes:
Hardware: 2Ghz Core2Duo, enough ram to not worry about paging
Some programs are not included, this is because the C code produced
compile errors. The Haskell code appears to be portable in *all* cases.
The average slowdown for running Haskell is only 1.3 times on OS X!
That's pretty damn good.
I'm sure some people will say "yeh, but you have to optimise your code
pretty heavily to get that kind of result". Interestingly, the
programs that have the biggest speed advantage over C here are also
the most "naïvely" written ones.
The thing that seems to make C slower is the implementation of malloc
in OS X. This has a couple of implications, first, if apple replaced
the malloc library, it would probably push the result back to the 1.7
times slower we see under Linux. Second, Fannkuch can probably be
optimised differently for Haskell to look even better -- at the
moment, the haskell code actually uses malloc!
Finally, that threading example... WOW! 65 times faster, and the code
is *really* simple. The C on the other hand is a massive mess.
Bob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080823/bcf3db95/attachment.htm
More information about the Haskell-Cafe
mailing list