[Haskell-cafe] Performance Issues
agl at imperialviolet.org
Tue Jan 29 11:37:42 EST 2008
> This computes 1000000!. This version takes 8m29.189s to execute.
> Replace foldr1 with foldr and that goes down to 7m4.315s. Replace
> product' with the Prelude product and it takes only 6m17.685s. Why is
> that so? I'm using ghc 6.8.1 on Mac OS X.
I'm guessing that the speedup with the Prelude product is because it's
a left fold. foldr goes to the end of the list and starts applying
backwards, up the thunks. A left fold just keeps an accumulator as it
The foldr1 to foldr speedup might be because foldr1 has three cases,
to foldr's two:
Adam Langley agl at imperialviolet.org
More information about the Haskell-Cafe