Cost center annotations - where/let difference

Hi, I was doing some heap profiles and ran into the following issue. Consider the program fib.hs: module Main where fib i | i == 0 || i == 1 = 1 | i > 1 = fib (i-1) + fib (i-2) | otherwise = 0 testWhere = {-# SCC "Where" #-} res where res = fib 35 testLet = {-# SCC "Let" #-} let res = fib 35 in res If I choose main = print testLet compile with: ghc --make -prof -auto-all -caf-all -O2 fib.hs and run: ./fib +RTS -hc -hCLet -L60 the fib.hp file will contain entries as expected. If I choose main = print testWhere compile with: ghc --make -prof -auto-all -caf-all -O2 fib.hs and run: ./fib +RTS -hc -hCWhere -L60 the fib.hp file will contain the timestamps, but entries for measured heap consumption. Can anyone please tell me, if this is the expected behavior? I'm not very experienced in benchmarking and was a bit irritated by that difference. Cheers, Daniel.

On Thursday 18 November 2010 11:24:24, Daniel Seidel wrote:
Hi,
I was doing some heap profiles and ran into the following issue.
Consider the program fib.hs:
module Main where
fib i | i == 0 || i == 1 = 1
| i > 1 = fib (i-1) + fib (i-2) | otherwise = 0
testWhere = {-# SCC "Where" #-} res where res = fib 35
testLet = {-# SCC "Let" #-} let res = fib 35 in res
Can anyone please tell me, if this is the expected behavior?
I think so. testWhere is equivalent to testLet2 = let res = fib35 in {-# SCC "Where" #-} res so the cost centre covers only the result, not the computation. To get the computation into the cost centre, use testWhere = res where res = {-# SCC "Where" #-} fib 35 which corresponds to let res = {-# SCC "Whatever" #-} fib 35 in res
I'm not very experienced in benchmarking and was a bit irritated by that difference.
Cheers, Daniel.
Ditto ;)

Thanks for the explanation :). Cheers, Daniel. On Thu, 2010-11-18 at 14:29 +0100, Daniel Fischer wrote:
On Thursday 18 November 2010 11:24:24, Daniel Seidel wrote:
Hi,
I was doing some heap profiles and ran into the following issue.
Consider the program fib.hs:
module Main where
fib i | i == 0 || i == 1 = 1
| i > 1 = fib (i-1) + fib (i-2) | otherwise = 0
testWhere = {-# SCC "Where" #-} res where res = fib 35
testLet = {-# SCC "Let" #-} let res = fib 35 in res
Can anyone please tell me, if this is the expected behavior?
I think so. testWhere is equivalent to
testLet2 = let res = fib35 in {-# SCC "Where" #-} res
so the cost centre covers only the result, not the computation. To get the computation into the cost centre, use
testWhere = res where res = {-# SCC "Where" #-} fib 35
which corresponds to
let res = {-# SCC "Whatever" #-} fib 35 in res
I'm not very experienced in benchmarking and was a bit irritated by that difference.
Cheers, Daniel.
Ditto ;)
participants (2)
-
Daniel Fischer
-
Daniel Seidel