[Haskell-cafe] A tale of three shootout entries

Don Stewart dons at galois.com
Tue Nov 27 14:17:36 EST 2007

> Simon Peyton-Jones wrote:
> >| Something I found with Dons version on my machine was that if I removed
> >| all the exclamation marks and the -fbang-patterns bit at the top it went
> >| about 20% faster as well as being much cleaner code, but with my very
> >| rudimentary understanding of Haskell I wasn't entirely sure it would
> >| produce the same results if I did this and didn't get round to checking.
> >
> >If, after investigation (and perhaps checking with Don) you find that 
> >adding bangs makes your program go slower, even though the function is in 
> >fact strict (otherwise it might go slower because it's just doing more 
> >work!) then I'd love to see a test case.
> Sorry, I don't understand the code, I've jumped in the deep-end before
> learning to swim, but I can now tell you it's producing the same results
> when I remove some of the exclamation marks. I've checked with an MD5 on
> the output.
> The timings in seconds for 10,000,000 iterations averaged over 5 runs.
> (There was quite a bit of variation.) Compiled with GHC 6.6.1. (I got
> stuck compiling it under 6.8) The fancy compile options are from the
> shootout page.
> Dons original program      13.26    compiled ghc --make
> Dons original program      12.54    compiled with -O -fglasgow-exts
>                                        -optc-mfpmath=sse -optc-msse2
>                                        -optc-march=pentium4
> Removed 3 bangs from rand  11.47    compiled ghc --make
> Removed 3 bangs from rand  11.57    compiled with -O -fglasgow-exts
>                                        -optc-mfpmath=sse -optc-msse2
>                                        -optc-march=pentium4
> The code below is Dons program from
> http://shootout.alioth.debian.org/gp4/benchmark.php?test=fasta&lang=ghc&id=0
> with a timing function added by me. The rand function is where I removed
> three exclamation marks to make the program faster. Previously I removed
> different combinations of bangs. Some bangs seem to make it faster and
> some seem to make it slower.

There may well have been changes to the strictness analyser that make
some of the bangs (or most) unnecessary now. Also, its very likely 
I didn't check all combinations of strict and lazy arguments for the
optimal evaluation strategy :)

If it seems to be running consitently faster (and producing better Core
code), by all means submit. I don't think this is a ghc bug or anything
like that though: just overuse of bangs, leading to unnecessary work.

-- Don

More information about the Haskell-Cafe mailing list