Measure CPU time

MuPAD® notebooks will be removed in a future release. Use MATLAB® live scripts instead.

MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.


time(a1, a2, …)


time() returns the total CPU time that was spent by the current MuPAD® process. It is measured in in milliseconds.

time(a1, a2, ...) returns the CPU time needed by the current MuPAD process to evaluate all arguments.

The result of time() comprises all computation time spent by the MuPAD process. This includes the time for system initialization and reading input (parsing). However, it excludes the time spent by other external processes, even if they were spawned from inside the MuPAD session or if they were started by a system command. Further, in an interactive session, the idle time between the execution of MuPAD commands is excluded.

If there are no running external process besides MuPAD, the timings returned by rtime(a1, a2, ...) and time(a1, a2, ...) roughly coincide.

The time returned by time is computed in a system-dependent way, usually counting the number of clock ticks of the system clock. Hence, the result is a multiple of the system's time unit and cannot be more precise than one such unit. The time unit is 10 milliseconds for many UNIX® systems.

On computers without “time-sharing”, such as the Macintosh computer, real time and CPU time roughly coincide.

time is a function of the system kernel.


Example 1

Do a time measurement and assign the computed value to an identifier at the same time. Note that the assignment needs extra parenthesis when passed as argument:

time((a := int(exp(x)*sin(x), x)))


delete a:

Alternatively, measure time for groups of statements as follows:

t0 := time():
time() - t0

Example 2

To obtain a more convenient output, multiply the measured time by the appropriate time unit:

time(isprime(2^1000000000 - 1))*unit::msec

Alternatively, use stringlib::formatTime:

stringlib::formatTime(time(isprime(2^1000000000 - 1)))


a1, a2, …

Arbitrary MuPAD objects

Return Values

Nonnegative integer giving the elapsed time in milliseconds.

See Also

MuPAD Functions