
TicToc

bgallarda
function tic() variable/G tictoc = startMSTimer end function toc() NVAR/Z tictoc variable ttTime = stopMSTimer(tictoc) printf "%g seconds\r", (ttTime/1e6) killvariables/Z tictoc end
Here is an example of the use of tic() and toc() functions to time some FFTs.
Function testTicToc() tic() variable i For(i=0;i<10000;i+=1) make/O/N=512 temp = gnoise(2) FFT temp Endfor killwaves/z temp toc() End
Output to history is:
•testTicToc()
1.3182 seconds
P.S. I vastly prefer IGOR to MATLAB, I just wanted to make inserting a timer into code a bit easier.

Forum

Support

Gallery
Igor Pro 9
Learn More
Igor XOP Toolkit
Learn More
Igor NIDAQ Tools MX
Learn More
In using the routines, I sometimes wanted to time my program, and sometimes I didn't. So, being lazy, I just commented out the toc() call at the end of my code. After a while, tic / toc no longer worked :( giving a NaN for the time value. After some head scratching, what is going on is that every time I ran the program with tic() active, a new MSTimer was started. After 10 were active, the timers were "full" and a further tic() call just returns -1. To add insult to injury, to "fix" the problem, I had to manually excute print stopMSTimer(0), print stopMSTimer(1), .... print stopMSTimer(9). Yuck!
Seems to me that a reasonable fix for this would be to allow one to call
with n={0,1, ..., 9}
Doing that would automatically reset and restart timer n (even if previously running). Calling StartMSTimer without an argument could give the old behavior. And while we're at it, maybe
could clear all timers? (-1 and -2 seem to be taken)
John Bechhoefer
Department of Physics
Simon Fraser University
Burnaby, BC, Canada
July 21, 2010 at 08:59 pm - Permalink