I'm trying to profile my program with SCC (Set Cost Center) annotations. What's the best way to find out how long it takes for a monad defined by a do statement to run? (It is illegal to put an SCC statement in a do block.) In other words, let's say I have:
do
x <- computeStuff
y <- computeStuff
return (x + y)
How do I find the total execution time for the two computeStuff
and the x + y
(instead of the construction time of the Monad)?
SCCs can be set on any expression. (do { ... })
is a valid expression. So is computeStuff
and return (x + y)
. The only thing that isn't an expression here is x <- computeStuff
. You say you want the total time, which I understand to mean the total time for the entire do block. But you can place SCCs anywhere inside the do block; for example, the following is perfectly valid.
computeStuff :: IO Int
computeStuff = return 0
test = {-# SCC "total" #-} (
do
x <- {-# SCC "x" #-} computeStuff
y <- {-# SCC "y" #-} computeStuff
return $ {-# SCC "x+y" #-} (x + y)
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With