3 The MLWorks Pervasive Library

3.6 Timing facilities: The Time structure

The Time structure is deprecated because it has been superseded by the Standard ML Basis library structures Time and Timer. The Basis structure Time corresponds to MLWorks.Time.Interval, and the Basis structure Timer to MLWorks.Time.Elapsed. Because Time is used by the MLWorks profiler, we have documented it minimally here. However, the profiler will use Basis time facilities in a future release.

The Time.Elapsed structure is for representing elapsed times.

The datatype T, values of which admit equality, is for representing elapsed times:

datatype T = ELAPSED of {real: Interval.T, 
                         user: Interval.T,
                         system: Interval.T,
                         gc: Interval.T}

Arithmetic operations are defined for use on elapsed times:

val * : T * real -> T
val + : T * T -> T
val - : T * T -> T
val / : T * real -> T

The function elapsed returns the time elapsed since (the current) MLWorks started:

val elapsed : unit -> T  

The function elapsed_since is provided for efficiency.

val elapsed_since : T -> T 

The format function formats an elapsed time into a string.

val format: T -> string

A typical output might be

"1.23 (user: 1.07, system: 0.06, gc: 0.03)"

The Time.Interval structure is for expressing the difference between two clock times.

The datatype T is the same as that for Elapsed.

eqtype T 

The functions from_real and to_real convert to and from floating-point representations of seconds:

      val from_real : real -> T
      val to_real : T -> real

Arithmetic operations are defined for use on intervals, too:

      val * : T * real -> T
      val + : T * T -> T
      val - : T * T -> T
      val / : T * real -> T
      val < : T * T -> bool
The following items format intervals:

val decimal_places : int ref
val format : T -> string

At the top level of the Time structure, there are items for expressing clock times.

The type of clock times:

eqtype time

Time zones:

datatype zone = GREENWICH | LOCAL

Arithmetic operations on clock times:

val + : time * Interval.T -> time
val - : time * Interval.T -> time
val < : time * time -> bool

The decode function converts a clock time to a string, and encode converts a string to a clock time:

val decode : string -> time
val encode : time -> string

Clock time formatting (ANSI C's strftime):

val format : string * zone * time -> string

The interval function returns the interval between two clock times:

val interval: time * time -> Interval.T

The current clock time can be found with the function now, which reads the clock:

val now : unit -> time 

The constant for time "zero":

val zero : time 


MLWorks Reference Manual (version 1.0) - 3 DEC 1996

Generated with Harlequin WebMaker