#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 702
#endif
module Agda.Utils.Time
( ClockTime
, getClockTime
, measureTime
, CPUTime(..)
) where
import Control.Monad.Trans
import System.CPUTime
#if MIN_VERSION_directory(1,1,1)
import qualified Data.Time
#else
import qualified System.Time
#endif
import Agda.Utils.Pretty
import Agda.Utils.String
type ClockTime =
#if MIN_VERSION_directory(1,1,1)
Data.Time.UTCTime
#else
System.Time.ClockTime
#endif
getClockTime :: IO ClockTime
getClockTime =
#if MIN_VERSION_directory(1,1,1)
Data.Time.getCurrentTime
#else
System.Time.getClockTime
#endif
newtype CPUTime = CPUTime Integer
deriving (Eq, Show, Ord, Num, Real, Enum, Integral)
instance Pretty CPUTime where
pretty (CPUTime ps) =
text $ showThousandSep (div ps 1000000000) ++ "ms"
measureTime :: MonadIO m => m a -> m (a, CPUTime)
measureTime m = do
start <- liftIO $ getCPUTime
x <- m
stop <- liftIO $ getCPUTime
return (x, CPUTime $ stop start)