[Haskell-beginners] Re: Is Haskell for me?

Jon Harrop jon at ffconsultancy.com
Fri Nov 20 23:36:42 EST 2009


On Friday 06 November 2009 17:19:50 Shawn Willden wrote:
> On Friday 06 November 2009 09:52:48 am Cory Knapp wrote:
> > Idiomatic Haskell won't be as fast as idiomatic C++, but it will blow
> > Python away.
>
> Based on the little bit of stuff I've done, I think I'd characterize it
> this way:  C++ will be maybe twice as fast as Haskell.  Maybe a little
> more, maybe a little less, depending on a lot of details.  For heavy
> computation, Python will be a couple orders of magnitude slower than both.
>
> IOW, Haskell is slower than C++ but it's in the same ballpark.
>
> Would anyone disagree?

The long-standing bug in GHC's garbage collector that makes writing a single 
boxed value into an array O(n) instead of O(1), because the GC dirties and 
retraverses the entire array, makes it impossible to write efficient Haskell 
code to solve many basic problems.

Here is a simple dictionary benchmark where Python is 4x faster than Haskell 
because this bug means it is impossible to implement a competitively- 
performant dictionary:

http://flyingfrogblog.blogspot.com/2009/04/f-vs-ocaml-vs-haskell-hash-table.html

Haskell's celebrated idiomatic quicksort is actually 6,000x slower than a 
traditional implementation on this machine and consumes asymptotically more 
memory (making it useless for quite mundane problems):

http://www.haskell.org/haskellwiki/Introduction#Quicksort_in_Haskell

Although people have created array-based quicksorts in Haskell the same perf 
bug in the GC means that a generic quicksort in Haskell would be 
asymptotically slower if it were given an array of boxed values.

As an aside, purity complicates the creation of a parallel generic quicksort 
because it is necessary to mutate different parts of the same array in 
parallel. AFAICT, writing an efficient parallel generic quicksort is an 
unsolved problem in Haskell.

Suffice to say, I cannot agree that Haskell is in the same ballpark as C++ in 
terms of performance. :-)

-- 
Dr Jon Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/?e


More information about the Beginners mailing list