up previous next
Counts cpu time
This function returns a
RAT
whose value is the user CPU usage in
seconds since the start of the program: this is the amount of time the
processor has dedicated to your computation, and may be rather less than
the real elapsed time if the computer is also busy with other tasks.
The most common usage is with
TimeFrom
as shown in the example;
it automatically computes the time difference and returns it as decimal string.
/**/ StartTime := CpuTime(); -- time in seconds since the start (a RAT)
/**/ --
/**/ -- .... long computation ....
/**/ --
/**/ PrintLn "Computation time: ", TimeFrom(StartTime);
/**/ -- Alternative use: compute TimeTaken as a RAT
/**/ StartTime := CpuTime();
/**/ --
/**/ -- .... long computation ....
/**/ --
/**/ EndTime := CpuTime();
/**/ TimeTaken := EndTime - StartTime; --> ugly if printed directly
/**/ PrintLn "Computation time: ", DecimalStr(TimeTaken);
|
You can use
DecimalStr
to see the value of
CpuTime
in a more easily
comprehensible form.