Expand/Shrink

time

Definition: atom a = time()
Description: Return the number of seconds since some fixed point in the past.
pwa/p2js: Supported.
Comments: To measure how long a section of code takes to execute, take the difference between two readings of time().

On Windows the resolution is normally about 0.01 seconds, whereas on Linux the resolution is normally 1 second.

To get the current time, use eg format_timedate(date(),"h:mmpm")
To display an elapsed time (over 60 seconds) as a human-readable string, use elapsed() (instead of ?).
Example:
constant ITERATIONS = 1000000
integer p
atom t0 = time(), loop_overhead
for i=1 to ITERATIONS do
    -- time an empty loop
end for
loop_overhead = time() - t0
t0 = time()
for i=1 to ITERATIONS do
    p = power(2, 20)
end for
? (time() - t0 - loop_overhead)/ITERATIONS
-- calculates time (in seconds) for ITERATIONS calls to power()
Implementation: via :%opTime in builtins\VM\pTime.e (an autoinclude)
See Also: date, format_timedate, elapsed