RunMat
  • Pricing
RunMat
GitHub
GitHub
Sign inTry in browser
DesktopRuntimePhysicsCADAdministrationAgent

Get RunMat updates

New releases, guides and examples.

Product+
  • Runtime
  • GPU
  • Parallel
  • Compile
  • Interop and MEX
  • Simulation
  • MCAD
  • ECAD
  • Enterprise
  • AI integrations
  • Pricing
  • Download
Math+
  • Signal processing
  • Linear algebra
  • Statistics
  • Curve fitting
  • Differential equations
  • Control systems
  • Optimization
  • Finance
  • Data and tables
  • Plotting
Physics+
  • Simulation overview
  • Structural
  • Thermal
  • Electromagnetic
  • Joule heating
  • Thermal stress
  • Acoustics
  • Fluid flow
  • Conjugate heat transfer
  • Fluid–structure
  • What is FEA
Industries+
  • Aerospace
  • Automotive and transportation
  • Defense
  • Electronics and semiconductors
  • Energy
  • Industrial machinery
  • Life sciences
  • Quantitative finance
Learn+
  • Guides
  • Docs
  • Function reference
  • Language reference
  • Migration guide
  • Changelog
  • MATLAB Online
  • MATLAB AI agent
  • For students
Compare+
  • RunMat vs MATLAB
  • RunMat vs Ansys
  • RunMat vs SOLIDWORKS
  • RunMat vs Altium
  • RunMat vs Cadence
  • RunMat vs COMSOL
  • RunMat vs Python
  • RunMat vs Julia
  • RunMat vs Physics AI
  • RunMat vs Octave
  • Benchmarks
  • MATLAB alternatives
  • All comparisons
Company+
  • About
  • Blog
  • Contact
  • Source code↗
  • License
  • Privacy
  • Terms

Product

  • Runtime
  • GPU
  • Parallel
  • Compile
  • Interop and MEX
  • Simulation
  • MCAD
  • ECAD
  • Enterprise
  • AI integrations
  • Pricing
  • Download

Math

  • Signal processing
  • Linear algebra
  • Statistics
  • Curve fitting
  • Differential equations
  • Control systems
  • Optimization
  • Finance
  • Data and tables
  • Plotting

Physics

  • Simulation overview
  • Structural
  • Thermal
  • Electromagnetic
  • Joule heating
  • Thermal stress
  • Acoustics
  • Fluid flow
  • Conjugate heat transfer
  • Fluid–structure
  • What is FEA

Industries

  • Aerospace
  • Automotive and transportation
  • Defense
  • Electronics and semiconductors
  • Energy
  • Industrial machinery
  • Life sciences
  • Quantitative finance

Learn

  • Guides
  • Docs
  • Function reference
  • Language reference
  • Migration guide
  • Changelog
  • MATLAB Online
  • MATLAB AI agent
  • For students

Compare

  • RunMat vs MATLAB
  • RunMat vs Ansys
  • RunMat vs SOLIDWORKS
  • RunMat vs Altium
  • RunMat vs Cadence
  • RunMat vs COMSOL
  • RunMat vs Python
  • RunMat vs Julia
  • RunMat vs Physics AI
  • RunMat vs Octave
  • Benchmarks
  • MATLAB alternatives
  • All comparisons

Company

  • About
  • Blog
  • Contact
  • Source code↗
  • License
  • Privacy
  • Terms
GitHubXLinkedIn

© Dystr, Inc. · RunMat v0.7.1, Nov 17, 2026

RunMat® is a registered trademark of Dystr, Inc. MATLAB® is a registered trademark of The MathWorks, Inc. RunMat is not affiliated with, endorsed by, or sponsored by The MathWorks, Inc.

/
See all docs
Builtin Reference
    • 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
    • toc

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.
NameTypeRequiredDefaultDescription
timerValNumericScalarYes—Opaque uint64 token returned by tic in this session.

Returns

elapsed
Type
NumericScalar
Description
Elapsed wall-clock seconds as a scalar double.
NameTypeDescription
elapsedNumericScalarElapsed 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
IdentifierWhenMessage
RunMat:toc:NoMatchingTictoc() is called without a prior tic() in the current session.toc: no matching tic
RunMat:toc:InvalidTimerHandleThe token is malformed, stale, or belongs to another session.toc: invalid timer handle
RunMat:toc:TooManyInputsMore than one input argument is supplied.toc: too many input arguments
RunMat:toc:TooManyOutputsMore than one output is requested from toc.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 = toc

Using 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.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.

Download RunMatOpen Sandbox
On this page
  • Syntax
  • Inputs
  • Returns
  • Errors
  • Behavior
  • Examples
  • Measuring elapsed time since the last tic
  • Using toc with an explicit tic handle
  • Timing nested stages with toc
  • Printing elapsed time without capturing output
  • Measuring immediately with toc(tic)
  • Using toc with coding agents
  • FAQ
  • Related Timing functions
  • Source you can read
  • About RunMat