Timing program execution

Timing program execution is useful for comparing various techniques to see which is faster. For such purposes times are needed at a fairly good resolution. Two routines are of interest.

Quick Index:


Built-in systime routine

The built-in function systime with an optional non-zero argument gives such times:

  print,systime(1)
     7.6936117e+08

The returned value is double precision and is the number of seconds since January 1, 1970.

Timing a piece of code is easy:


  t = systime(1)
  ... code to time ...
  print,systime(1)-t



Timer utility

This is a utility based on systime. It allows multiple timers to be in operation.

  timer,/help
   Measure elapsed time between calls.
   timer, [dt]
     dt = optionally returned elapsed time in seconds.    out
   Keywords:
     /START  starts timer.
     /STOP   stops timer (actually updates elapsed time).
     /PRINT  prints timer report.
     NUMBER = n. Select timer number to use (default = 0).
        Timer numbers 0 through 9 may be used.
     COMMENT = cmt_text. Causes /PRINT to print:
       cmt_text elapsed time: hh:mm:ss (nnn sec)
   Notes:
    Examples:
    timer, /start  use this call to start timer.
    timer, /stop, /print, dt   use this call to stop timer
      and print start, stop, elapsed time.  This example also
      returns elapsed time in seconds.
    Timer must be started before any elapsed time is available.
    Timer may be stopped any number of times after starting once, and
    the elapsed time is the time since the last timer start.
    timer, /start, number=5   starts timer number 5.
    timer, /stop, /print, number=5   stops timer number 5
    and prints result.

Some examples:

  timer,/start
  . . .
  timer,/stop,/print
         Timer 0 started: 1994 Oct 6 08:17:01 Thu
         Timer 0 stopped: 1994 Oct 6 08:17:08 Thu
         Elapsed time: 00:00:06 (6.8097200 sec)

  timer,/start
  . . .
  timer,/stop,/print,comment='Image processing' 
         Image processing elapsed time: 00:00:06 (6.2396981 sec)

IDL main page.