The TIC and TOC routines work together to allow you to check the running time of your IDL programs. The TIC routine stores the initial system time. TOC records the final system time, then calculates and displays the total elapsed time (final time - system time).

You may call the TIC routine as either a procedure or a function. When you call TIC as a procedure, the TIC and TOC routines print out the elapsed time between the calls. When you call TIC as a function, the TOC routine measures the elapsed time for that specific call. This allows you to nest the TIC and TOC calls to measure the time within subroutines and loops.

Example


Following is a simple example of using TIC and TOC to measure the length of time it takes IDL to create a plot. Copy and paste the following to the IDL command line:

 
; Calculate the length of time needed to graph a sinewave
TIC
sw = SIN(2.0*FINDGEN(200)*!PI/25.0) * EXP(-0.02*FINDGEN(200))
p1 = PLOT(sw, '-r')
TOC

IDL prints:

% Time elapsed: 0.94500017 seconds.

Now, call TIC as a function, to measure the time for nested subroutines. Be sure to copy and paste all of the lines at the same time.

 
; Grab the initial system time with TIC
TIC 
for i=0, 3 do begin & $
 
  ; Start another clock named FFT
  ; combined with the iteration number
  clock = TIC('FFT' + STRTRIM(i, 2)) & $
  r = FFT(RANDOMU(seed, 1729, 1729)) & $
   
  ; For each iteration grab the end system time, 
  ; then calculate and and print out the elapsed time 
  TOC, clock & $
endfor
; Grab the final system  for the entire loop
; and calculate and print the total elapsed time
TOC 

IDL prints:

% Time elapsed FFT0: 1.0139999 seconds.
% Time elapsed FFT1: 0.98699999 seconds.
% Time elapsed FFT2: 1.0000000 seconds.
% Time elapsed FFT3: 0.99300003 seconds.
% Time elapsed: 4.9909999 seconds.

Syntax


TIC [, /PROFILER]

or

ClockName = TIC( [Name] [, /PROFILER] )

Return Value


If TIC is called as a function, the return value (ClockName) is an identifier associated with that particular call to TIC. This identifier can then be passed into the TOC routine to print out the elapsed time for that particular "clock."

Arguments


Name

Set this optional argument to a string giving a name to be associated with this particular call to TIC. This name will then be printed out when the TOC routine is called using the ClockName. If Name is not specified then IDL uses a null string in its place.

Keywords


PROFILER

Set this keyword to turn on the PROFILER for all user and system routines. Before turning on PROFILER, IDL resets any previous profiling results. The PROFILER will automatically be turned off when you call the TOC routine with no arguments. See TOC for an example of using the PROFILER.

Note: Because the PROFILER introduces an overhead to all IDL function calls, the elapsed times will be slightly longer when PROFILER is on. You should also make sure to call the TOC routine with no arguments to disable profiling.

Tip: If you are using the IDL Workbench, IDL will automatically refresh the Profiler view when TOC is called.

Version History


8.2.2 Introduced

See Also


PROFILER, TOC