stop
Builtin index · REPL & diagnostics
stop(t)
Input: t · Output: no output
What it is
Takes one argument, t (a timer object). Freezes the timer and resets the count to zero (unlike pause, which keeps it); returns none. Also stops any on elapsed(t)/on elapsedOnce(t) registration from firing until started again. The handle remains valid and reusable.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
stop(t) | t —not documented yet | no output | Freezes the timer and resets the count to zero (unlike pause, which keeps it); returns none. The handle remains valid and reusable. |
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() # 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
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}")
elapsed >= 0: true stop returns: 0.001746 done, acc = 5000050000
from tour
How it works
stop(t) — freeze AND reset the count to zero (unlike pause, which keeps it). The handle stays valid and reusable: start(t) after stop begins a fresh count from zero. Also stops any on elapsed(t)/on elapsedOnce(t) registration from firing (checked live by run_for) until started again.
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.