Qu

toc

Builtin index · REPL & diagnostics

result = toc()

Input: no input · Output: result

What it is

Takes no arguments.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = toc()no input
result number
Returns a number: elapsed seconds (float, fractional) since the last tic(). Does not clear the start, so repeated toc() calls measure from the same tic() — useful for lap-timing a loop. Errors if called before any tic(). timer.elapsed() and timer.stop() are both sugar for this (see below) — toc() was already a non-resetting peek, so both aliases inherit that for free.

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

tic()
# ... work ...

dt = toc()          # a number, in seconds

from agent-guide

tic()
for i in 1 to 1000000
    x = sqrt(i)
end
elapsed_s = toc()
print("took {elapsed_s:.4f}s")
output
took 0.0079s

from repl-diagnostics

sizes = [100, 1000, 10000, 100000]
times = []
for n in sizes
    tic()
    total = 0
    for j in 1 to n
        total = total + j
    end
    dt = toc()
    times = append(times, dt)
end
label = estimate_complexity(sizes, times)   # e.g. "O(n)"

print("estimated complexity label = {label}")

from repl-diagnostics