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