Qu

tic

Builtin index · REPL & diagnostics

tic()

Input: no input · Output: no output

What it is

Takes no arguments. Starts (or restarts) the single global stopwatch. timer.start() is sugar for this — see below.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
tic()no inputno outputTakes no arguments. Starts (or restarts) the single global stopwatch. timer.start() is sugar for this — see below.

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

How it works

tic()/toc() (MATLAB-style) — real wall-clock timing. toc() doesn't clear the start, so repeated calls measure from the same tic() (matches MATLAB, useful for lap-timing a loop).

From the note above this builtin in the interpreter, where the reasoning was written down as it was built.