2 % (c) The GRASP/AQUA Project, Glasgow University, 1995-1997
4 \section[CPUTime]{Haskell 1.4 CPU Time Library}
9 getCPUTime, -- :: IO Integer
10 cpuTimePrecision -- :: Integer
13 import PrelBase (Int(..), indexIntArray#, Addr(..) )
14 import ArrBase --(ByteArray(..))
22 Computation @getCPUTime@ returns the number of picoseconds CPU time
23 used by the current program. The precision of this result is
24 implementation-dependent.
26 The @cpuTimePrecision@ constant is the resolution (in picoseconds!) of
30 getCPUTime :: IO Integer
32 newIntArray (0,3) `thenIO_Prim` \ marr ->
33 unsafeFreezeByteArray marr `thenIO_Prim` \ barr@(ByteArray _ frozen#) ->
34 _ccall_ getCPUTime barr `thenIO_Prim` \ ptr ->
35 if (ptr::Addr) /= ``NULL'' then
36 return ((fromIntegral (I# (indexIntArray# frozen# 0#)) * 1000000000 +
37 fromIntegral (I# (indexIntArray# frozen# 1#)) +
38 fromIntegral (I# (indexIntArray# frozen# 2#)) * 1000000000 +
39 fromIntegral (I# (indexIntArray# frozen# 3#))) * 1000)
41 fail (IOError Nothing UnsupportedOperation "getCPUTime: can't get CPU time")
43 cpuTimePrecision :: Integer
44 cpuTimePrecision = round ((1000000000000::Integer) %
45 fromInt (unsafePerformPrimIO (_ccall_ clockTicks )))