[Haskell-cafe] #haskell works

Andrew Coppin andrewcoppin at btinternet.com
Fri Dec 14 15:12:18 EST 2007


Many people have written words to the effect that the #haskell IRC 
channel is just bursting with helpful Haskellers who are endlessly 
friendly and seemingly able to help solve any problem. Personally, this 
has never been my experience. (More like there's 300 people idling and 
nobody ever actually speaks...)

I am pleased to report that last night I was on #haskell and I did in 
fact get lots of useful help, from a number of people. So first of all, 
thanks for that guys!

It all relates to this simple program:

http://hpaste.org/4438

I pointed out that you can write a complex explicit loop in Java, and 
that you can translate the same thing into Haskell, and it works. But in 
Haskell, you can also do it by composing a couple of functions, and it's 
much easier to read. Somebody else countered that while this is all very 
cute, it can never be efficient. To which I obviously countered that 
stream fusion *makes* it efficient.

The numbers generated are thus:

Program with no particular optimisations: 0.35 seconds.
Program with stream fusion [and GHC HEAD]: 0.25 seconds.
Program with stream fusion and ByteString: 0.05 seconds.

Surely you'd have to work pretty hard to get that kind of speed even in 
C. ;-)

...erm, actually no. Somebody sat down and wrote something in five 
minutes that takes 0.005 seconds. Oops!

So it seems even with ByteStrings and stream fusion, we're still 10x 
slower than naive C. :-( You can console yourself that maybe 5 
milliseconds is too short a time span to reliably measure, and maybe the 
speed difference is just down to the OS caching the file in RAM or 
something. Maybe a benchmark of something that takes tens of seconds 
would be better. All I know is that once again, it seems Haskell isn't 
as fast as I thought... *sigh*

Well anyway, a few years ago we didn't have fusion, and we didn't have 
ByteString. A few years ago, the program would have taken 0.35 seconds. 
The end. Today, with a few import statements and compiler switches, the 
exact same code takes 0.05 seconds. Tomorrow, who knows? Maybe I'm being 
overly optimistic, but... ;-)



More information about the Haskell-Cafe mailing list