Next Previous Up Top Contents Index

4.6 Timing: the Timer structure

printTiming

Function

Structure

Shell.Timer

Type

val printTiming: {function: 'a -> 'b, name: string, outputter: string -> unit} -> 'a -> 'b

Syntax

printTiming {function=f, name=n, outputter=o} a -> g

Arguments

f
A function.

n
A string.

a
An argument for f.

o
A function that prints out a string.

Values

g
The return value for f applied to a.

Description

This function returns the value of f applied to a, and as a side effect it prints the time taken to evaluate the expression.

Example

Define the following function:

fun g x = let 
  fun f 0 _ = ()
   | f n m = (f m 0; f (n-1) m)
     in  f x x
  end;

Below is an example of applying printTiming to g with an argument of 1000:

MLWorks>printTiming {function=g, 
                     name="hello",
                     outputter=print} 1000;
Time for hello : 0.54 (user: 0.49, system: 0.00, gc: 0.00)
val it : unit = ()
MLWorks>

MLWorks Reference Manual version 2.0 - 29 Jul 1998

Next Previous Up Top Contents Index

Generated with Harlequin WebMaker