[Haskell-cafe] -O2 compile option can give speed increase over -O. Fasta shootout program test runs.

Richard Kelsall r.kelsall at millstream.com
Mon Jul 16 14:49:54 EDT 2007

I have been playing with the Fasta program in the shootout to see if
I can make it umm faster. Starting from dons program on this page and
adding some timing calculations as suggested on this wiki page


I added different OPTIONS into the top line of the program did a
ghc --make fasta.hs   and ran it each time with  fasta 2500000
(This is one tenth of the shootout figure.) These runs all keep the
existing OPTIONS of  -fbang-patterns -fexcess-precision

   Seconds   OPTIONS Added
   -------   -------------
    40.5        -funbox-strict-fields
    40.4                      {-# INLINE rand #-}
    17.2        -O
    17.0        -O  -fvia-C
    14.4        -O  -optc-march=pentium4
    11.5        -O2
    11.2        -O3
    11.5        -O3           {-# INLINE rand #-}
    11.3        -O2 -optc-march=pentium4

There was a bit of variation, I've averaged over two runs. This is on
an Intel Pentium D 2.66GHz running W2K and GHC 6.6.1.

It seems the -O2 option can give a significant speed increase relative
to just the -O option. This is contrary to the documentation which says


it won't make any difference. I guess it's program, architecture and
operating system specific, but according to these figures the -O2 option
seems well worth a try for programs that need speed. It may be that
we sacrifice bounds checking or something important with -O2, I don't


More information about the Haskell-Cafe mailing list