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# )
14 import ArrBase ( ByteArray(..), newIntArray, unsafeFreezeByteArray )
18 import Unsafe ( unsafePerformIO )
24 Computation @getCPUTime@ returns the number of picoseconds CPU time
25 used by the current program. The precision of this result is
26 implementation-dependent.
28 The @cpuTimePrecision@ constant is the resolution (in picoseconds!) of
32 getCPUTime :: IO Integer
34 stToIO (newIntArray (0,3)) >>= \ marr ->
35 stToIO (unsafeFreezeByteArray marr) >>= \ barr@(ByteArray _ frozen#) ->
36 _ccall_ getCPUTime barr >>= \ ptr ->
37 if (ptr::Addr) /= ``NULL'' then
38 return ((fromIntegral (I# (indexIntArray# frozen# 0#)) * 1000000000 +
39 fromIntegral (I# (indexIntArray# frozen# 1#)) +
40 fromIntegral (I# (indexIntArray# frozen# 2#)) * 1000000000 +
41 fromIntegral (I# (indexIntArray# frozen# 3#))) * 1000)
43 fail (IOError Nothing UnsupportedOperation
44 "getCPUTime: can't get CPU time")
46 cpuTimePrecision :: Integer
47 cpuTimePrecision = round ((1000000000000::Integer) %
48 fromInt (unsafePerformIO (_ccall_ clockTicks )))