RunMat
  • Pricing
RunMat
GitHub
GitHub
DownloadSign InTry in Browser
DesktopRuntimeServer
RunMat

Run math blazing fast

GitHubX (Twitter)LinkedIn

Company

  • About
  • Pricing
  • Contact

Explore

  • RunMat for academia
  • RunMat vs MATLAB Online
  • Benchmarks

Get product updates and release notes from the RunMat team.

© 2026 Dystr · Made withfor the scientific community.

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.

LicensePrivacy
/
See all docs
Builtin Reference
    • cputime
    • pause
    • tic
    • timeit
    • timer
    • timerfind
    • timerfindall
    • toc

tic — Start a high-resolution stopwatch timer and optionally return a handle for paired toc reads.

tic starts a high-resolution stopwatch used by toc to report elapsed wall-clock seconds. Assign its opaque uint64 token when you need to measure from a specific start time.

Syntax

timerVal = tic()

Returns

NameTypeDescription
timerValNumericScalarTimer handle used by toc.

Errors

IdentifierWhenMessage
RunMat:tic:StateLockFailedInternal stopwatch state cannot be acquired.tic: failed to acquire stopwatch state

How tic works

  • Uses the host's monotonic clock for nanosecond-resolution timing.
  • Each call makes its start time the latest stopwatch. toc without inputs can read that latest start repeatedly; it does not consume the timer.
  • Returns an opaque uint64 token. The bits identify a monotonic-clock instant and must not be treated as a numeric timestamp or duration.
  • Executes entirely on the CPU. There are no GPU variants because tic interacts with wall-clock state.
  • Calling toc before tic raises the MATLAB-compatible error RunMat:toc:NoMatchingTic.

Examples

Measuring a simple loop

tic;
for k = 1:1e5
    sqrt(k);
end
elapsed = toc

Capturing and reusing the tic handle

t = tic;
heavyComputation();
elapsed = toc(t)

Nesting timers for staged profiling

outer = tic;      % Keep the outer timer token
stage1();         % Work you want to measure once
inner = tic;      % Start a second stopwatch
stage2();
innerT = toc(inner);  % Elapsed time for stage2 only
outerT = toc(outer);  % Elapsed time for both stages

Measuring asynchronous work

token = tic;
future = backgroundTask();
wait(future);
elapsed = toc(token)

Resetting the stopwatch after a measurement

elapsed1 = toc(tic);  % Equivalent to separate tic/toc calls
pause(0.1);
elapsed2 = toc(tic);  % Starts a new timer immediately

Using tic with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how tic changes the result.

Run a small tic example, explain the result, then change one input and compare the output.

FAQ

Does tic print anything when called without a semicolon?⌄

No. tic is marked as a sink builtin, so scripts do not display the returned handle unless you assign it or explicitly request output.

Is the returned handle portable across sessions?⌄

No. The handle encodes a monotonic timestamp that is only meaningful within the current RunMat process. Passing it to another session or saving it to disk is undefined behaviour, matching MATLAB.

Can I run tic on a worker thread?⌄

Yes. Stopwatch state is process-wide, so concurrent scripts should retain and pass their own uint64 tokens when timings might interleave.

How accurate is the measurement?⌄

tic relies on a monotonic clock (via runmat_time::Instant), typically providing microsecond or better precision. The actual resolution depends on your operating system. There is no artificial jitter or throttling introduced by RunMat.

Does tic participate in GPU fusion?⌄

No. Timer builtins are tagged as CPU-only. Expressions containing tic are always executed on the host, and any GPU-resident tensors are gathered automatically by surrounding code when necessary.

Related Timing functions

cputime · pause · timeit · timer · timerfind · timerfindall · toc

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how tic is executed, line by line, in Rust.

  • View the source for tic in Rust on GitHub
  • Learn how the RunMat runtime works
  • Found a bug? Open an issue with a minimal reproduction.

About RunMat

RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 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
  • Returns
  • Errors
  • How tic works
  • Examples
  • Measuring a simple loop
  • Capturing and reusing the tic handle
  • Nesting timers for staged profiling
  • Measuring asynchronous work
  • Resetting the stopwatch after a measurement
  • Using tic with coding agents
  • FAQ
  • Related Timing functions
  • Open-source implementation
  • About RunMat