toc — Read elapsed seconds since a session-owned tic start.
toc returns elapsed wall-clock seconds since the latest tic or since an explicit opaque uint64 token from this session. Called without an output destination, it prints the elapsed-time line instead of an implicit ans value.
Syntax
elapsed = toc()
elapsed = toc(timerVal)Inputs
timerVal- Type
NumericScalar- Required
- Yes
- Description
- Opaque uint64 token returned by tic in this session.
Returns
elapsed- Type
NumericScalar- Description
- Elapsed wall-clock seconds as a scalar double.
Errors
RunMat:toc:NoMatchingTic- When
- toc() is called without a prior tic() in the current session.
- Message
toc: no matching tic
RunMat:toc:InvalidTimerHandle- When
- The token is malformed, stale, or belongs to another session.
- Message
toc: invalid timer handle
RunMat:toc:TooManyInputs- When
- More than one input argument is supplied.
- Message
toc: too many input arguments
RunMat:toc:TooManyOutputs- When
- More than one output is requested from toc.
- Message
toc: too many output arguments
Behavior
toc() reads the latest start without consuming it. toc(token) reads the start associated with a published token; repeated reads remain valid.
Malformed, forged, stale, foreign-session, and legacy double-valued timer handles raise RunMat:toc:InvalidTimerHandle before clock access.
The elapsed result is a scalar double in seconds. The monotonic timing service controls resolution; no GPU provider or fusion stage is involved.
Examples
Measuring elapsed time since the last tic
tic;
pause(0.25);
elapsed = tocUsing toc with an explicit tic handle
token = tic;
x = sum(1:1000);
elapsed = toc(token)Timing nested stages with toc
outer = tic;
x = sum(1:1000);
inner = tic;
y = sum(1:2000);
stage2Time = toc(inner);
totalTime = toc(outer)Printing elapsed time without capturing output
tic;
x = sum(1:1000);
toc;Measuring immediately with toc(tic)
elapsed = toc(tic);Using toc with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how toc changes the result.
Run a small toc example, explain the result, then change one input and compare the output.
FAQ
What happens if I call toc before tic?⌄
It raises RunMat:toc:NoMatchingTic when this session has no latest start.
Does toc remove the matching tic?⌄
No. Both forms are read operations, so repeated calls report elapsed time from the same start.
Can I reuse a tic handle after calling toc(t)?⌄
Yes, within the same session. The token remains valid until that session ends.
Does toc print output?⌄
A standalone toc or toc; prints an Elapsed time is ... seconds. line. Assigning its result returns a scalar double without that line; a semicolon on the standalone call does not suppress its explicit print.
Is toc affected by GPU execution or fusion?⌄
No. It reads the host monotonic timing service.
How accurate is the reported time?⌄
Resolution depends on the host monotonic clock and scheduler.
Related Timing functions
cputime · pause · set.BusyMode · set.ErrorFcn · set.ExecutionMode · set.Name · set.ObjectVisibility · set.Period · set.StartDelay · set.StartFcn · set.StopFcn · set.Tag · set.TasksToExecute · set.TimerFcn · set.UserData · tic · timeit · timer · timerfind · timerfindall
Source you can read
Every RunMat function's source is public. Read exactly how toc is executed, line by line, in Rust.
- View the source for toc in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.