import Data.Time
time :: String -> IO a -> IO a
time str a = do
start <- getCurrentTime
v <- a
end <- getCurrentTime
let diff = diffUTCTime end start
putStrLn $ str ++ showNominalDiffTime (diff)
return v
showNominalDiffTime :: NominalDiffTime -> String
showNominalDiffTime nTime = let timeString = show nTime in
take (length timeString - 1) timeString ++ " sec"
fun :: IO (Int, [Int])
fun = do
i <- time "product: " $ return $! product [1..10000] -- testing strictness : evaluated
j <- time "product list: " $ return $! map (\_ -> product [1..10000]) [1..3] -- testing strictness : not evaluated List is in hnf
return (i, j)
main = fun