~ubuntu-branches/ubuntu/wily/agda/wily-proposed

« back to all changes in this revision

Viewing changes to src/full/Agda/Utils/Time.hs

  • Committer: Package Import Robot
  • Author(s): Iain Lane, d5cf60f
  • Date: 2015-05-20 13:08:33 UTC
  • mfrom: (1.1.7)
  • Revision ID: package-import@ubuntu.com-20150520130833-cdcmhagwsouna237
Tags: 2.4.2.2-2
[d5cf60f] Depend on ${shlibs:Depends}, to get libc (& maybe other) deps

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
{-# LANGUAGE CPP #-}
2
2
 
 
3
#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 702
 
4
{-# OPTIONS_GHC -fno-warn-identities #-}
 
5
#endif
 
6
-- To avoid warning on derived Integral instance for CPUTime
 
7
 
 
8
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
 
9
 
3
10
-- | Time-related utilities.
4
11
 
5
12
module Agda.Utils.Time
6
13
  ( ClockTime
7
14
  , getClockTime
 
15
  , measureTime
 
16
  , CPUTime(..)
8
17
  ) where
9
18
 
 
19
import Control.Monad.Trans
 
20
import System.CPUTime
 
21
 
10
22
#if MIN_VERSION_directory(1,1,1)
11
23
import qualified Data.Time
12
24
#else
13
25
import qualified System.Time
14
26
#endif
15
27
 
 
28
import Agda.Utils.Pretty
 
29
import Agda.Utils.String
 
30
 
16
31
-- | Timestamps.
17
32
 
18
33
type ClockTime =
31
46
#else
32
47
  System.Time.getClockTime
33
48
#endif
 
49
 
 
50
-- | CPU time in pico (10^-12) seconds.
 
51
 
 
52
newtype CPUTime = CPUTime Integer
 
53
  deriving (Eq, Show, Ord, Num, Real, Enum, Integral)
 
54
 
 
55
-- | Print CPU time in milli (10^-3) seconds.
 
56
 
 
57
instance Pretty CPUTime where
 
58
  pretty (CPUTime ps) =
 
59
    text $ showThousandSep (div ps 1000000000) ++ "ms"
 
60
 
 
61
-- | Measure the time of a computation. Returns the
 
62
measureTime :: MonadIO m => m a -> m (a, CPUTime)
 
63
measureTime m = do
 
64
  start <- liftIO $ getCPUTime
 
65
  x     <- m
 
66
  stop  <- liftIO $ getCPUTime
 
67
  return (x, CPUTime $ stop - start)
 
68