Measure CPU time
This functionality does not run in MATLAB.
time()
time(a1, a2, …
)
time()
returns the total CPU time in milliseconds
that was spent by the current MuPAD^{®} process.
time(a1, a2, ...)
returns the CPU time needed
by the current MuPAD process to evaluate all arguments.
The result of time()
comprises all the 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 no external process besides MuPAD are running, the timings
returned by rtime(a1, a2, ...)
and time(a1,
a2, ...)
roughly coincide.
The time returned by time
is computed in
a systemdependent 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 1 such unit. E.g., the time
unit is 10 milliseconds for many UNIX^{®} systems.
On computers without "timesharing", such as the Macintosh computer, real time and CPU time roughly coincide.
time
is a function of the system kernel.
This example shows how to 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)))
a
delete a:
Alternatively, one may time groups of statements in the following way:
t0 := time(): command1 command2 ... time()  t0
Here we use rtime
to compute the elapsed
hours, minutes and seconds since this session was started:
t := rtime()/1000: h := trunc(t/3600): m := trunc(t/60  h*60): s := trunc(t  m*60  h*3600):
print(Unquoted, "This session is running for " . h . " hours, " . m . " minutes and " . s . " seconds.")
This session is running for 0 hours, 0 minutes and 10 seconds.
delete t, h, m, s:
To obtain a nicer output, the measured time can be multiplied with the appropriate time unit:
time(isprime(2^1000000000  1))*unit::msec
Alternatively, use stringlib::formatTime
:
stringlib::formatTime(time(isprime(2^1000000000  1)))

Arbitrary MuPAD objects 
Nonnegative integer giving the elapsed time in milliseconds.