cputime — Return total CPU time used by the current RunMat process.

cputime returns the total CPU time used by the current RunMat process in seconds. It is intended for legacy MATLAB compatibility; prefer timeit or tic/toc for wall-clock benchmarking.

Syntax

t = cputime()

Returns

NameTypeDescription
tNumericScalarTotal CPU time used by the current RunMat process in seconds.

Errors

IdentifierWhenMessage
RunMat:cputime:TooManyInputsAny input arguments are supplied.cputime: too many input arguments
RunMat:cputime:UnavailableThe host platform reports that process CPU time is unavailable.cputime: process CPU time is unavailable

How cputime works

  • Takes no input arguments.
  • Returns a finite, nonnegative scalar double in seconds.
  • Native Unix builds use host process CPU accounting via getrusage.
  • Native Windows builds use host process CPU accounting via GetProcessTimes.
  • WASM/browser builds do not expose process CPU accounting, so RunMat returns monotonic seconds since the WASM runtime first used cputime; differences remain useful for compatibility code, but the measurement is wall-clock elapsed time rather than true CPU time.
  • GPU providers are never consulted, and the builtin is excluded from fusion plans.

Example

Measure CPU Time Used By Code

tStart = cputime;
for k = 1:100000
    sqrt(k);
end
tElapsed = cputime - tStart

Expected output:

tElapsed = <seconds>

Using cputime with coding agents

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

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

FAQ

How is cputime different from tic and toc?

cputime measures CPU time consumed by the process on native targets. tic/toc measure wall-clock elapsed time.

Why does WASM use a wall-clock fallback?

Browsers do not expose process CPU time. RunMat keeps the no-argument scalar API available so MATLAB compatibility code that subtracts two calls still runs.

Does cputime reset?

No. Like MATLAB, native builds return total CPU time since the current process started. On WASM, the wall-clock fallback is measured from the first cputime call. To measure a section of code, subtract two readings.

Open-source implementation

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

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.