2 % (c) The GRASP/AQUA Project, Glasgow University, 1995-1997
4 \section[CPUTime]{Haskell 1.4 CPU Time Library}
7 {-# OPTIONS -fno-implicit-prelude #-}
11 getCPUTime, -- :: IO Integer
12 cpuTimePrecision -- :: Integer
16 import PrelArr ( ByteArray(..), newIntArray, unsafeFreezeByteArray )
22 import PrelUnsafe ( unsafePerformIO )
28 Computation @getCPUTime@ returns the number of picoseconds CPU time
29 used by the current program. The precision of this result is
30 implementation-dependent.
32 The @cpuTimePrecision@ constant is the resolution (in picoseconds!) of
36 getCPUTime :: IO Integer
38 stToIO (newIntArray (0,3)) >>= \ marr ->
39 stToIO (unsafeFreezeByteArray marr) >>= \ barr@(ByteArray _ frozen#) ->
40 _ccall_ getCPUTime barr >>= \ ptr ->
41 if (ptr::Addr) /= ``NULL'' then
42 return ((fromIntegral (I# (indexIntArray# frozen# 0#)) * 1000000000 +
43 fromIntegral (I# (indexIntArray# frozen# 1#)) +
44 fromIntegral (I# (indexIntArray# frozen# 2#)) * 1000000000 +
45 fromIntegral (I# (indexIntArray# frozen# 3#))) * 1000)
47 fail (IOError Nothing UnsupportedOperation
48 "getCPUTime: can't get CPU time")
50 cpuTimePrecision :: Integer
51 cpuTimePrecision = round ((1000000000000::Integer) %
52 fromInt (unsafePerformIO (_ccall_ clockTicks )))