The Standard ML Basis Library


The Timer structure

The Timer structure provides facilities for measuring the passing of wall clock (real) time and the amount of time the running process has had the CPU (user time), has been active in the OS kernel (system time), and has spent on garbage collection (GC time).


Synopsis

signature TIMER
structure Timer : TIMER

Interface

type cpu_timer
type real_timer
val startCPUTimer : unit -> cpu_timer
val checkCPUTimer : cpu_timer -> {usr : Time.time, sys : Time.time, gc : Time.time}
val totalCPUTimer : unit -> cpu_timer
val startRealTimer : unit -> real_timer
val checkRealTimer : real_timer -> Time.time
val totalRealTimer : unit -> real_timer

Description

type cpu_timer

type real_timer
Type real_timer is the type of wall clock (real) timers, and cpu_timer is the type of CPU timers.

startCPUTimer ()
returns a CPU timer that measures the time the process is computing (has control of the CPU) starting at this call.

checkCPUTimer ct
returns the user time, system time and GC time that have accumulated since the timer ct was started. The amount of GC time is also included in the user time.

totalCPUTimer ()
returns a CPU timer that measures the time the process is computing (has control of the CPU) starting at some system-dependent initialization time.

startRealTimer ()
returns a wall clock (real) timer that measures how much time passes, starting from the time of this call.

checkRealTimer rt
returns the amount of (real) time that has passed since the timer rt was started.

totalRealTimer ()
returns a wall clock (real) timer that measures how much time passes, starting from some system-dependent initialization time.


Discussion

The accuracy of the user, system and GC times depends on the resolution of the system timer and the function call overhead in the OS interface. In particular, very small intervals might not be reported accurately.

On a Unix system, the user and system time reported by a CPU timer do not include the time spent in child processes.

Implementation note:

Some operating systems may lack the ability to measure CPU time consumption, in which case the real time should be returned instead.

See Also

Time

[ INDEX | TOP | Parent | Root ]

Last Modified October 31, 1997
Comments to John Reppy.
Copyright © 1997 Bell Labs, Lucent Technologies