;+ ; timeit ; ; PURPOSE: ; test how long a given IDL command takes to execute. ; ; NOTES: ; ; takes a string specifying an idl command. Executes it some number of times ; (default=5) and prints the mean execution time. ; ; This actually has to be implemented as a batch file so that it executes at ; the same level of IDL rather than going inside of a procedure or function ; call, since then none of your variables would be accessible and the ; statement you want to time would presumably not work. ; ; USAGE: ; ; IDL> cmdstr="some string of commands" ; [optional: IDL> timeitloops=] ; IDL> @timeit ; ; HISTORY: ; 2001-07-25 by Marshall Perrin ; ;- if not(keyword_set(timeitloops)) then timeitloops=5 timeitr=fltarr(timeitloops) for timeit=0,timeitloops-1 do begin &$ timeit1=systime(/seconds) &$ timeite=execute(cmdstr) &$ timeit2=systime(/seconds) &$ timeitr[timeit]=timeit2-timeit1 &$ print,"TIMEIT: execution took "+strc(timeitr[timeit])," seconds" &$ endfor timeitmean = mean(timeitr) timeitstddev = stddev(timeitr) print,"TIMEIT: Average "+strc(timeitmean)+", stddev "+strc(timeitstddev)