next up previous contents index
Next: reset! Up: Timer Previous: gc   Contents   Index


read


Usage

read t


Signature

read: % $\to$ MachineInteger


Parameter Type Description
t % The timer to read


Description

Reads the timer t without stopping it.


Returns

Returns the total accumulated time in milliseconds by all the start/stop cycles since t was created or last reset. This times includes any eventual garbage collection time (see gc to extract this information). If t is running, the time since the last start is added in, and t is not stopped or affected.


Example

The following function takes a positive MachineInteger $n$ as input, computes and prints a machine approximation of $\sum_{i=1}^n 1/i$, and returns the CPU time needed to compute it, but not the time needed to print it.
timeHarmonic(n:MachineInteger):MachineInteger == {
        import from MachineInteger, SingleFloat, Timer, Character, TextWriter;
        t := timer();
        m:SingleFloat := 1;
        start! t;
        for i in 2..n repeat m := m + 1 / (i::SingleFloat);
        stop! t;
        stdout << "H" << n << " = " << m << newline;
        read t;
}


See Also

gc, start!, stop!


next up previous contents index
Next: reset! Up: Timer Previous: gc   Contents   Index
Manuel Bronstein 2004-06-28