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

timeit — Measure function-handle execution time by repeated evaluation.

t = timeit(f) repeatedly evaluates zero-argument function handle f and returns the median execution time in seconds. The optional output count controls how many outputs are requested from each invocation.

Syntax

t = timeit(f)
t = timeit(f, numOutputs)

Inputs

NameTypeRequiredDefaultDescription
fAnyYes—Zero-input function handle to benchmark.
numOutputsIntegerScalarNo1Requested output count for invoking the benchmarked handle.

Returns

NameTypeDescription
tNumericScalarMedian execution time per invocation in seconds.

Errors

IdentifierWhenMessage
RunMat:timeit:TooManyInputsMore than two input arguments are supplied.timeit: too many input arguments
RunMat:timeit:NumOutputsScalarnumOutputs is not a scalar numeric/integer value.timeit: numOutputs must be a scalar numeric value
RunMat:timeit:NumOutputsFinitenumOutputs is NaN or infinite.timeit: numOutputs must be finite
RunMat:timeit:NumOutputsNonnegativenumOutputs is negative.timeit: numOutputs must be a nonnegative integer
RunMat:timeit:NumOutputsIntegernumOutputs has a non-integer numeric value.timeit: numOutputs must be an integer value
RunMat:timeit:EmptyFunctionHandleA function-handle string or payload is empty after trimming.timeit: empty function handle string
RunMat:timeit:ExpectedAtHandleStringA string/char function handle does not begin with '@'.timeit: expected a function handle string beginning with '@'
RunMat:timeit:HandleKindFunction handle argument is not a scalar string/char or callable handle value.timeit: function handle must be a string scalar or function handle
RunMat:timeit:FirstArgKindFirst argument is not a function handle value.timeit: first argument must be a function handle

How timeit works

  • Executes f repeatedly, adjusting the inner loop count until a single batch takes at least a few milliseconds or the function is slow enough.
  • Collects multiple samples (at least seven batches) and returns the median per-invocation time, which is robust against outliers.
  • Drops the outputs produced by f; you should perform any validation that depends on those outputs inside the handle.
  • Leaves GPU residency untouched—if f launches GPU kernels, they execute on the active provider. Insert wait(gpuDevice) inside the handle if you need explicit synchronisation.

Examples

Timing a simple anonymous function

f = @() sin(rand(1000, 1));
t = timeit(f)

Comparing two implementations

A = rand(1e5, 1);
slow = @() sum(A .* A);
fast = @() sumsq(A);

slowTime = timeit(slow);
fastTime = timeit(fast)

Timing a function that returns no outputs

logMessage = @() fprintf("Iteration complete\n");
t = timeit(logMessage, 0)

Timing a multiple-output function

svdTime = timeit(@() svd(rand(256)), 3)

Measuring GPU-bound work

gfun = @() gather(sin(gpuArray.rand(4096, 1)));
tgpu = timeit(gfun)

Timing a preallocation helper

makeMatrix = @() zeros(2048, 2048);
t = timeit(makeMatrix)

Using timeit with coding agents

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

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

FAQ

What does timeit return?⌄

A scalar double containing the median runtime per invocation in seconds.

How many runs does timeit perform?⌄

It automatically selects a loop count so each batch lasts a few milliseconds, collecting at least seven batches.

Does timeit synchronise GPU kernels?⌄

No. Insert wait(gpuDevice) inside the handle when you need explicit synchronisation.

Can I time functions that require inputs?⌄

Yes. Capture them in the handle, for example timeit(@() myfun(A, B)).

How do I time a function with multiple outputs?⌄

Pass timeit(@() svd(A), 3). The runtime requests three outputs from the handle and discards the returned values. Native integer output counts are available in runmat compatibility mode.

Why do successive runs differ slightly?⌄

Normal system jitter, cache effects, and GPU scheduling can change runtimes slightly; the median mitigates outliers.

Can timeit time scripts?⌄

Wrap the script body in a function handle so it becomes zero-argument, then call timeit on that handle.

Does timeit participate in fusion or JIT tiers?⌄

It executes the provided handle; any tiering or fusion happens inside the timed function.

What happens if the function errors?⌄

The error is propagated immediately and timing stops.

Is there a limit on runs?⌄

Yes. timeit caps the inner loop at about one million iterations to avoid runaway measurements.

Related Timing functions

cputime · pause · tic · timer · timerfind · timerfindall · toc

Open-source implementation

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

  • View the source for timeit 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
  • Inputs
  • Returns
  • Errors
  • How timeit works
  • Examples
  • Timing a simple anonymous function
  • Comparing two implementations
  • Timing a function that returns no outputs
  • Timing a multiple-output function
  • Measuring GPU-bound work
  • Timing a preallocation helper
  • Using timeit with coding agents
  • FAQ
  • Related Timing functions
  • Open-source implementation
  • About RunMat