Getting Started Documentation Glish Learn More Programming Contact Us
Version 1.9 Build 1556
News FAQ
Search Home


next up previous contents index
Next: stopwatch.help - Function Up: stopwatch - Tool Previous: stopwatch.show - Function


stopwatch.timefunc - Function



Package utility
Module misc
Tool stopwatch


time a function


Synopsis
timefunc(func, niter, name, quiet)



Description
Run a function, and display the runtime. The function to be timed should take no arguments, but constant arguments may be passed in by defining a function expression in the call. After the function is run, the numerical value of the runtime can be retrieved from the time with value.



Arguments

func   Function to be timed
niter   Number of iterations
    Default: 1
name   Output label
    Default: '' or func
quiet   Suppress status output?
    Default: F



Example
                                      # a function that might take a while
- function iter_sin (iter=10,len=10000) { 
+ v:=[1:len]; while (iter>0) { iter:=iter-1; v := sin(v); } v; }

- tim.timefunc(iter_sin)              # time it
Timing function...
return value is [0.462957899 0.471936887 0.137069347 -0.448762012 ... ] 
Function took 0.15s  to run
F 
-                                     # can supply args this way
+ tim.timefunc(function () { iter_sin(1000) })
Timing function...
return value is [0.0545929715 0.0546066474 0.0510562464 -0.0545696198 ... ] 
Function took 9.31s  to run
F 
-                                     # or this way
+ function tmpfunc() { iter_sin(1000) }
tim.timefunc(tmpfunc,quiet=T)                
F 
- tim.show()
timer is STOPPED, value is 9.21s      # timings are reasonably consistent
F
-                                     # can average multiple runs
+ t.timefunc(function() { iter_sin(1000)}, 3, 'big_demo')  
Timing function big_demo 3 times...
return value is [0.0545929715 0.0546066474 0.0510562464 -0.0545696198 ... ] 
Function big_demo took 9.20s to run
return value is [0.0545929715 0.0546066474 0.0510562464 -0.0545696198 ... ] 
Function big_demo took 9.26s to run
return value is [0.0545929715 0.0546066474 0.0510562464 -0.0545696198 ... ] 
Function big_demo took 9.31s to run

Function big_demo took an average of 9.26s to run, over 3 iterations
T

The func argument may also be be a string containing the name of the function to be timed. In this case, the name argument will default to the function name.





next up previous contents index
Next: stopwatch.help - Function Up: stopwatch - Tool Previous: stopwatch.show - Function   Contents   Index
Please send questions or comments about AIPS++ to aips2-request@nrao.edu.
Copyright © 1995-2000 Associated Universities Inc., Washington, D.C.

Return to AIPS++ Home Page
2006-10-15