
Calling Sequence


SystemUTCClock
ProcessClock
ThreadClock()


Description


•

A clock object provides access to the current time, returning a Time object that represents the moment at which the clock is queried by invoking its Now method.

•

Each clock is associated with a socalled "epoch", which represents the origin of the time system that the clock implements. The epoch of a clock is accessed via its Epoch method.

•

The epoch of a clock may be defined or undefined. A clock with an undefined epoch has a definite, but unknown, origin.

•

Also associated with any clock object is a "precision" that can be queried by using the Precision method of the clock. The precision of a clock represents the fineness with which the clock measures time. It is designated by a unit name denoting the smallest interval of time that may be resolved by the clock. A clock with a smaller unit of precision measures time more precisely than one with a larger unit of precision. For example, a clock with microsecond precision is able to distinguish points in time that differ by one microsecond, and is more precise than a clock with second precision, which can only distinguish points of time that differ by one or more seconds.

•

The precision of a clock should not be confused with its accuracy. The latter is a measure of how close a measurement is to its true value. The accuracy of a clock cannot be known, in general, as it depends upon the configuration of the underlying operating system and, perhaps, hardware.

•

Each clock is of type Clock. Use the type command to check whether a Maple expression is of type Clock.



Methods


•

All clocks implement the following methods.

Now returns a Time object representing the current time

Precision returns the name of a unit designating a clock's precision

Epoch returns the epoch of a clock



•

The most important method of a clock object is the Now method. It returns a Time object representing the moment of time it was invoked, on the time system the clock represents. Numerically, this is a positive or negative count of the number of units of the clock's precision from the epoch of the clock, which may or may not be defined. For a clock with an undefined epoch, it is only meaningful to compare Time values produced by the same clock.

•

The Precision method of a clock object returns a unit name designating the precision of the clock; that is, the fineness with which the clock measures time.

•

The Epoch method of a clock returns a value representing the "origin", or zeropoint of the time scale measured by that clock. Time values produced by clocks with a defined epoch are comparable and can be combined arithmetically. Time values produced by clocks with an undefined epoch can only be meaningfully compared if they are produced by the same (identical) clock object.



The System UTC Clock


•

A single object, SystemUTCClock, provides access to the UTC time provided by the underlying operating system.

•

Because the SystemUTCClock is determined uniquely by the operating system, values produced by it in different Maple processes are expected to agree and can be meaningfully compared and combined.



The Process Clock


•

The ProcessClock object allows you to query the CPU time of the current Maple process. It has an undefined epoch, and a precision (typically nanosecond) determined by the underlying operating system.

•

The process clock is unique to the Maple process in which it exists. Time values produced by its Now method are meaningful only within a single Maple process. They represent the amount of CPU time elapsed since their epoch, which is a definite, but undefined point in time.



Thread Clocks


•

A ThreadClock object allows you to query the CPU time of the current thread in a Maple process. Each ThreadClock has an undefined epoch, and a precision (typically nanosecond) determined by the underlying operating system.

•

Since thread clocks are unique to the thread in which they are invoked, a different thread clock must be created via a constructor call of the form ThreadClock() in the current thread.



Examples


>

$\mathrm{type}\left(\mathrm{SystemUTCClock}\,'\mathrm{Clock}'\right)$

>

$\mathrm{type}\left(\mathrm{ProcessClock}\,'\mathrm{Clock}'\right)$

>

$\mathrm{Now}\left(\mathrm{SystemUTCClock}\right)$

${\mathrm{Time}}{}\left({1583379593211}{\,}{1}{\,}{\mathrm{clock}}{\=}\left({\mathbf{module}}\left({}\right)\phantom{\rule[0.0ex]{0.5em}{0.0ex}}{...}\phantom{\rule[0.0ex]{0.5em}{0.0ex}}{\mathbf{end\; module}}\right)\right)$
 (3) 
>

$\mathrm{Epoch}\left(\mathrm{SystemUTCClock}\right)$

${\mathrm{Date}}{}\left({1970}{\,}{1}{\,}{1}{\,}{0}{\,}{0}{\,}{0}{\,}{\mathrm{timezone}}{\=}{''UTC''}{\,}{\mathrm{coefficient}}{\=}{1}\right)$
 (4) 
>

$\mathrm{Precision}\left(\mathrm{SystemUTCClock}\right)$

${\mathrm{millisecond}}$
 (5) 
>

$\mathrm{Now}\left(\mathrm{ProcessClock}\right)$

${\mathrm{Time}}{}\left({188889870}{\,}{1}{\,}{\mathrm{clock}}{\=}\left({\mathbf{module}}\left({}\right)\phantom{\rule[0.0ex]{0.5em}{0.0ex}}{...}\phantom{\rule[0.0ex]{0.5em}{0.0ex}}{\mathbf{end\; module}}\right)\right)$
 (6) 
>

$\mathrm{Epoch}\left(\mathrm{ProcessClock}\right)$

${\mathrm{undefined}}$
 (7) 
>

$\mathrm{Epoch}\left(\mathrm{ThreadClock}\left(\right)\right)$

${\mathrm{undefined}}$
 (8) 


Compatibility


•

The Clock command was introduced in Maple 2018.



