elapsed
Builtin index · REPL & diagnostics
result = elapsed(t)
Input: t · Output: result
What it is
Takes one argument, t (a timer object).
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = elapsed(t) | t numbernot documented yet | result number | Returns a number: elapsed seconds so far. A pure read — never stops or resets the timer, callable regardless of running state. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
timer.start()
acc = 0
for k = 0 to 100000
acc += k
end for
e = timer.elapsed()
print("elapsed >= 0: {e >= 0}")
s = timer.stop()
print("stop returns: {s}")
print("done, acc = {acc}")
output
elapsed >= 0: true stop returns: 0.000696 done, acc = 5000050000
from tour
function heavy_computation()
return sum(sin(1 to 100000))
end function
function more_work()
return sum(cos(1 to 100000))
end function
timer.start() # same as tic()
heavy_computation()
mid = timer.elapsed() # peek — does NOT reset, callable again
more_work()
total = timer.stop() # same as toc() — also a non-resetting read
from repl-diagnostics
How it works
elapsed(t) — real elapsed seconds so far. A pure read: never stops or resets the timer, callable anytime regardless of running state.
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.