rtime, time
-- measure real
time and execution timertime()
returns the total real time in milliseconds
spent in the current session.
rtime(a1, a2...)
returns the real time needed to
evaluate all arguments.
time()
returns the total execution time spent in the
current session.
time(a1, a2...)
returns the execution time needed to
evaluate all arguments.
rtime()
rtime(a1, a2...)
time()
time(a1, a2...)
a1, a2... |
- | arbitrary MuPAD objects |
a nonnegative integer
rtime
returns the time in milliseconds. Note, however,
that at present the last three digits are always 0, i.e., the precision
of the time measured by rtime
is only one second.time()
comprises all the computation
time spent by MuPAD. This includes the time for system
initialization and reading input (parsing). However, it excludes the
time spent by other programs running at the same time, even if they
were started by a system
command.time
is computed in a
system-dependent way, usually counting the number of clock ticks of the
system clock. Hence, the time returned by time
is a
multiple of the system's time unit and cannot be more precise than 1
unit. E.g., the time unit is 10 milliseconds for many UNIX
systems.rtime
and time
are functions 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:
>> rtime((a := int(exp(x)*sin(x), x)))
9000
>> a
sin(x) exp(x) cos(x) exp(x) ------------- - ------------- 2 2
>> delete a:
Alternatively, one may time groups of statements in the following way:
>> t0 := rtime(): command1 command2 ... rtime() - 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 := 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((a := isprime(2^1000 - 1)))*msec
700 msec
>> time((a := isprime(2^1000 - 1)))*sec/1000.0
0.7 sec
>> delete a: