1 (* Copyright (C
) 1999-2006 Henry Cejtin
, Matthew Fluet
, Suresh
2 * Jagannathan
, and Stephen Weeks
.
3 * Copyright (C
) 1997-2000 NEC Research Institute
.
5 * MLton is released under a BSD
-style license
.
6 * See the file MLton
-LICENSE for details
.
9 structure Timer
: TIMER
=
13 datatype t
= T
of {sys
: Time
.time
, usr
: Time
.time
}
17 fun (T
{sys
, usr
}) - (T
{sys
= s
', usr
= u
'}) =
18 T
{sys
= Time
.- (sys
, s
'),
19 usr
= Time
.- (usr
, u
')}
22 type cpu_timer
= {gc
: SysUsr
.t
, self
: SysUsr
.t
}
24 fun startCPUTimer (): cpu_timer
=
26 val {gc
= {utime
= gcu
, stime
= gcs
, ...},
27 self
= {utime
= selfu
, stime
= selfs
}, ...} =
30 {gc
= SysUsr
.T
{sys
= gcs
, usr
= gcu
},
31 self
= SysUsr
.T
{sys
= selfs
, usr
= selfu
}}
34 fun checkCPUTimes
{gc
, self
} =
36 val {gc
= g
', self
= s
'} = startCPUTimer ()
37 val gc
= SysUsr
.- (g
', gc
)
38 val self
= SysUsr
.- (s
', self
)
40 {gc
= SysUsr
.export gc
,
41 nongc
= SysUsr
.export (SysUsr
.- (self
, gc
))}
44 fun checkCPUTimer timer
=
46 val {nongc
, gc
} = checkCPUTimes timer
48 {sys
= Time
.+ (#sys gc
, #sys nongc
),
49 usr
= Time
.+ (#usr gc
, #usr nongc
)}
54 val t
= startCPUTimer ()
59 val checkGCTime
= #usr
o #gc
o checkCPUTimes
61 type real_timer
= Time
.time
63 fun startRealTimer (): real_timer
= Time
.now ()
65 fun checkRealTimer (t
: real_timer
): Time
.time
=
66 Time
.- (startRealTimer (), t
)
70 val t
= startRealTimer ()