Commit 95f9334a authored by Simon Marlow's avatar Simon Marlow

GHCi: use real time instead of CPU time for :set -s

CPU time is never very accurate, and it broke completely with
-fexternal-interpreter which runs the interpreted computations in a
separate process.
parent e68195a9
......@@ -48,7 +48,7 @@ import Exception
import Numeric
import Data.Array
import Data.IORef
import System.CPUTime
import Data.Time
import System.Environment
import System.IO
import Control.Monad
......@@ -348,18 +348,18 @@ timeIt getAllocs action
= do b <- lift $ isOptionSet ShowTiming
if not b
then action
else do time1 <- liftIO $ getCPUTime
else do time1 <- liftIO $ getCurrentTime
a <- action
let allocs = getAllocs a
time2 <- liftIO $ getCPUTime
time2 <- liftIO $ getCurrentTime
dflags <- getDynFlags
liftIO $ printTimes dflags allocs (time2 - time1)
let period = time2 `diffUTCTime` time1
liftIO $ printTimes dflags allocs (realToFrac period)
return a
printTimes :: DynFlags -> Maybe Integer -> Integer -> IO ()
printTimes dflags mallocs psecs
= do let secs = (fromIntegral psecs / (10^(12::Integer))) :: Float
secs_str = showFFloat (Just 2) secs
printTimes :: DynFlags -> Maybe Integer -> Double -> IO ()
printTimes dflags mallocs secs
= do let secs_str = showFFloat (Just 2) secs
putStrLn (showSDoc dflags (
parens (text (secs_str "") <+> text "secs" <> comma <+>
case mallocs of
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment