[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

'timer' routine enclosed




I'll bet this has been done before (I seem to recall a
'Yorick' routine that may
have inspired this one).  But I couldn't find it, so I wrote
it and now I'm sharing.
Profuse on-line help should explain how to run it.  Code is
short, the help and
doc are long.

-- Dave --


pro timer,ti,lbl,new=new

 nmandparm = 2
 IF n_params(0) lt nmandparm THEN BEGIN
 QHELP:
   print," "
   print,"Key in:"
   print,"  timer,ti,lbl
   print,"Where:"
   print,"  Example:"
   print,"  timer,ti,'Start'
   print,"  mysubroutine,fake,args
   print,"  timer,ti,'Mysubroutine'
   print,"  c = a + b
   print,"  timer,ti,'Add'
   print,"  ;long section of code
   print,"  timer,ti,'Long section'"
   print," "
   print,"And then to view the timings you might wish to
use:"
   print,"  ptimer,ti"
   print,"  Mysubroutine       9.7179999"
   print,"  Add                2.4690001"
   print,"  Long section       2.0500000"
   print," "
   print,"To 'start over'"
   print,"  timer,ti,'new project',/new
   return
 ENDIF

           ;DOESN'T EXIST YET?  START OVER?
 IF (nel(ti) eq 0) OR keyword_set(new) THEN BEGIN
   dubble = systime(1)
   ti = {timertype,time:0.0D,label:string(lbl)}
   ti.time = dubble
 ENDIF ELSE BEGIN
           ;APPEND NEW ONE
   q=ti(0)  &  q.time=systime(1)  &  q.label=string(lbl)
   ti = [ti,q]
 ENDELSE
END


pro ptimer,ti

 nmandparm = 1
 IF n_params(0) lt nmandparm THEN BEGIN
 QHELP:
   print," "
   print,"Key in:"
   print,"  ptimer,ti
   print,"Where:"
   print,"  ti is a structure from 'timer'"
   print," "
   print,"Where:"
   print,"  Example:"
   print,"  timer,ti,'Start'
   print,"  mysubroutine,fake,args
   print,"  timer,ti,'Mysubroutine'
   print,"  c = a + b
   print,"  timer,ti,'Add'
   print,"  ;long section of code
   print,"  timer,ti,'Long section'"
   print," "
   print,"And then to view the timings you might wish to
use:"
   print,"  ptimer,ti"
   print,"  Mysubroutine       9.7179999"
   print,"  Add                2.4690001"
   print,"  Long section       2.0500000"
   print," "
   print,"To 'start over'"
   print,"  timer,ti,'new project',/new
   return
 ENDIF


 ;print times from 'timer' routine
 ;'ti' is the 'timer' structure
 vals = ti.time
 diff = shift(vals,-1)-vals
 FOR i=1,n_elements(vals)-1 DO BEGIN
  print,ti(i).label,diff(i-1)
 ENDFOR
END