[Haskell-cafe] Performance Issues

Adrian Neumann aneumann at inf.fu-berlin.de
Tue Jan 29 07:10:09 EST 2008

Hello Haskell-Cafe!

I've read about Control.Parallel and wanted to give it a try. Here's  
what I wrote:

import Control.Parallel
import Data.List

splitList :: [Integer] -> [[Integer]]
splitList = unfoldr f where
     f [] = Nothing
     f ~x = Just (splitAt 30000 x)

map' :: (a->b) -> [a] -> [b]
map' f (x:xs) =fx `par` (seq mfxs (fx:mfxs)) where
     fx = f x
     mfxs = map' f xs
map' f [] = []

product' :: [Integer] -> Integer
product' = foldr1 (\x y -> seq x (x*y))

fak :: Integer -> Integer
fak n = product' $ map' product' (splitList [1..n])

main = putStrLn $ seq (fak 1000000) "done"

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.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 186 bytes
Desc: Signierter Teil der Nachricht
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20080129/49166898/PGP.bin

More information about the Haskell-Cafe mailing list