[project @ 1996-01-11 14:06:51 by partain]
[ghc-hetmet.git] / ghc / lib / haskell-1.3 / LibCPUTime.lhs
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1995
3 %
4 \section[LibCPUTime]{Haskell 1.3 CPU Time Library}
5
6 \begin{code}
7 module LibCPUTime where
8
9 import PreludeGlaST
10
11 getCPUTime :: IO Integer
12 getCPUTime =
13     newIntArray (0,3)                               `thenPrimIO` \ marr ->
14     unsafeFreezeByteArray marr                      `thenPrimIO` \ barr@(_ByteArray _ frozen#) ->
15     _ccall_ getCPUTime barr                         `thenPrimIO` \ ptr ->
16     if (ptr::_Addr) /= ``NULL'' then
17         return (fromInt (I# (indexIntArray# frozen# 0#)) * 1000000000 + 
18                 fromInt (I# (indexIntArray# frozen# 1#)) + 
19                 fromInt (I# (indexIntArray# frozen# 2#)) * 1000000000 + 
20                 fromInt (I# (indexIntArray# frozen# 3#)))
21     else
22         failWith (UnsupportedOperation "can't get CPU time")
23
24 \end{code}
25
26 Computation $getCPUTime$ returns the number of nanoseconds CPU time
27 used by the current program.  The precision of this result is
28 implementation-dependent.
29
30
31
32
33
34