Previous Page Next Page Contents

rtime, time -- measure real time and execution time

Introduction

rtime() 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.

Call(s)

rtime()
rtime(a1, a2...)
time()
time(a1, a2...)

Parameters

a1, a2... - arbitrary MuPAD objects

Returns

a nonnegative integer

Related Functions

prog::profile

Details

Example 1

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

Example 2

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:

Example 3

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:

Background

Changes




Do you have questions or comments?


Copyright © SciFace Software GmbH & Co. KG 2000