Getting Started | Documentation | Glish | Learn More | Programming | Contact Us |
Version 1.9 Build 1556 |
|
Package | utility | |
Module | misc | |
Tool | stopwatch |
func | Function to be timed | ||
niter | Number of iterations | ||
Default: | 1 | ||
name | Output label | ||
Default: | '' or func | ||
quiet | Suppress status output? | ||
Default: | F |
# 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.