Timing sections of code is relatively simple in IGOR, using startMStimer and stopMStimer, but the two following functions make it even more simple, much like it is in MATLAB.

function tic()
    variable/G tictoc = startMSTimer

function toc()
    NVAR/Z tictoc
    variable ttTime = stopMSTimer(tictoc)
    printf "%g seconds\r", (ttTime/1e6)
    killvariables/Z tictoc

Here is an example of the use of tic() and toc() functions to time some FFTs.

Function testTicToc()

    variable i
        make/O/N=512 temp = gnoise(2)
        FFT temp
    killwaves/z temp

Output to history is:

1.3182 seconds

P.S. I vastly prefer IGOR to MATLAB, I just wanted to make inserting a timer into code a bit easier.
This is a handy set of routines. I've run into a "bug", however, that is more of a WM "feature"....

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




Igor Pro 8

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More