[Haskell-cafe] GHC vs GCC

Jan-Willem Maessen jmaessen at alum.mit.edu
Sat Mar 27 10:36:08 EDT 2010

On Sat, Mar 27, 2010 at 12:43 AM, Rafael Almeida <almeidaraf at gmail.com>wrote:

> On Fri, Mar 26, 2010 at 6:49 PM, Jason Dagit <dagit at codersbase.com> wrote:
> >
> >
> > On Fri, Mar 26, 2010 at 2:33 PM, Bryan O'Sullivan <bos at serpentine.com>
> > wrote:
> >>
> >> On Fri, Mar 26, 2010 at 10:46 AM, Rafael Cunha de Almeida
> >> <almeidaraf at gmail.com> wrote:
> >>>
> >>> During a talk with a friend I came up with two programs, one written in
> >>> C and another in haskell.
> >>
> >> Your Haskell code builds a huge thunked accumulator value, so of course
> >> it's slow (put bang patterns on all arguments). Also, you should use rem
> >> instead of mod. Make those tiny changes and you'll get a 5x speedup, to
> half
> >> the performance of the C code.
> >
> > Interesting.  I had to add -fvia-C to get within half the performance of
> C.
> > Just bang patterns and rem and I'm 1/5th of C.  I'm on a x86_64 machine.
> I
> > wonder if that plays in.
> >
> > Jason
> >
> Using bang patterns didn't help almost anything here. Using rem
> instead of mod made the time go from 45s to 40s. Now, using -fvia-C
> really helped (when I used rem but not using mod). It went down to
> 10s.

It's worth pointing out that there's a bit of bang-pattern mysticism going
on in this conversation (which has not been uncommon of late!).  A non-buggy
strictness analyzer should expose the strictness of these functions without
difficulty.  If bang patterns make any difference at all with a -O flag,
either there's a strictness analysis bug, or some very interesting effects
from shifting the order of forcing of strict variables.

Putting in bang patterns is a good idea to plug the obvious space leak when
run without optimization, but isn't going to make a difference for
optimizing compilation of obviously-strict functions.

-Jan-Willem Maessen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100327/ce450269/attachment.html

More information about the Haskell-Cafe mailing list