[Haskell-cafe] sum $ map f xs ... ghc-7.10 performance regression?
Johannes Waldmann
johannes.waldmann at htwk-leipzig.de
Mon Dec 14 22:30:52 UTC 2015
Is there a difference between "sum $ map f xs" and "sum $! map f xs"?
I would think no, since "$!" just evaluates the argument to WHNF,
so it would evaluate just the first cons of the list.
This little program
main = print $ sum $ map bitcount [0, 4 .. 2^24-1 ]
bitcount :: Int -> Int
bitcount x =
if x > 0 then let (d,m) = divMod x 2 in bitcount d + m else 0
runs in 1.6 seconds when compiled with -O2
on ghc-7.6.3, ghc-7.8.4,
but takes 3.2 seconds on ghc-7.10.[1-3]. Why?
when I change the main function (note: $ => $!) to
main = print $ sum $! map bitcount [0, 4 .. 2^24-1 ]
and compile with 7.10.[1-3], then it also runs in 1.6 seconds.
(I can write a bug report but I want to check
whether I am missing something obvious)
- J.W.
More information about the Haskell-Cafe
mailing list