Documentation |
Measure real time
This functionality does not run in MATLAB.
rtime() rtime(a1, a2, …)
rtime() returns the real time in milliseconds that elapsed since the start of the current MuPAD^{®} session.
rtime(a1, a2, ...) returns the real time needed to evaluate all arguments.
The result of rtime is the real time. Thus, rtime can be used to measure the total time spent by the MuPAD process as well as by external processes spawned from inside the MuPAD session. Note that an interactive call of rtime() is not very useful, since the idle time of the user is included. However, rtime(a1, a2, ...) often yields a useful and more realistic timing than time(a1, a2, ...) if the evaluation of the arguments spawns external processes. Such a situation may arise in a numerical computation because some routines of the numeric library call external numerical tools using hardware floats. Cf. Example 4.
If no external process besides MuPAD are running, the timings returned by rtime(a1, a2, ...) and time(a1, a2, ...) roughly coincide.
On computers without "time-sharing", such as the Macintosh computer, real time and CPU time roughly coincide.
rtime 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)))