comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: timing in IDL....
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: timing in IDL.... [message #1903] Sun, 10 April 1994 23:17
stl is currently offline  stl
Messages: 70
Registered: February 1994
Member
In article <Cny0KC.B6F@usenet.ucs.indiana.edu> ratnakar amaravadi <amaravad@silver.ucs.indiana.edu> writes:
> I am interested in estimating the CPU time taken by an IDL routine in
> my main IDL program. How can I do this. I did follow the IDL manual
> instructions to use the IDL SYSTIME command before and after calling
> the routine. I would like to know how valid these results are? Are
> these results dependent on system load or is it the actual amount
> of CPU time used.
>
>
> Also does any of you have experience in speeding up an IDL program
> by eliminating IF statements. I eliminated IF statements in my
> routine, and found that the routine got slower. Any body with
> similar experiences.
>
hello,

I have included the timer.pro routine at the bottom of this posting. It
allows you to start and stop timers before and after routines, etc.
pretty handy. I beleive the best way to use this is compile everything
before you begin testing times.

As for youar above questions, on optimizing code, I would suggest
reading chapter 12 in the 3.5 user manual, it explains tons and tons
about optimizing. But basicly any removal of loops is a good thing, use
as many system routines as possible, don't convert types often,
calculate as much outside of loops as possible, look at order of
operation, and if memory problems exist (or if using huge arrays) use
the temporary() command. Most importanty, if using large arrays, access
them in momory order, row wise (in otherwords in the same order they are
stored in memory).

I would be glad to help with any specific questions. Hope this helps.

-stephen

begin code
here________________________________________________________ ___

;----------------------------------------------------------- --
;+
; NAME:
; TIMER
;
; PURPOSE:
; Measure elapsed time between calls.
;
; CATEGORY:
; Date/Time
;
; CALLING SEQUENCE:
; timer, [dt]
;
; INPUTS:
; KEYWORD PARAMETERS:
; 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)
; OUTPUTS:
; dt = optionally returned elapsed time in seconds. out
; COMMON BLOCKS:
; timer_com
; NOTES:
; 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.
; MODIFICATION HISTORY:
; R. Sterner, 17 Nov, 1989
; Added to idlmeteo from the JHU/APL-Library
;
; Copyright (C) 1989, Johns Hopkins University/Applied Physics Laboratory
; This software may be used, copied, or redistributed as long as it is not
; sold and this copyright notice is reproduced on each copy made. This
; routine is provided as is without any express or implied warranties
; whatsoever. Other limitations apply as described in the file disclaimer.txt.
;-
;----------------------------------------------------------- --

pro timer, dt, start=strt, stop=stp, print=prnt, number=numb, $
comment=cmt, help=hlp

common timer_com, t1, t2, dtc

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

if n_elements(t1) eq 0 then begin
t1 = strarr(10)
t2 = strarr(10)
dtc = dblarr(10)
endif

c = 0 ; Keyword detected.
num = 0
if keyword_set(numb) then num = numb ; Default timer number.
snum = strtrim(num,2)

if keyword_set(strt) then begin
t1(num) = systime()
c = 1
endif

if keyword_set(stp) or (n_params(0) gt 0) then begin
if t1(num) eq '' then begin
print,' Error: Timer '+snum+' has not been started.'
print,' Do timer, /start first.'
return
endif
t2(num) = systime()
dt = secstr(getwrd(t2(num),3)) - secstr(getwrd(t1(num),3))
dtc(num) = dt
c = 1
endif

if keyword_set(prnt) then begin
if t1(num) eq '' then begin
print,' Error: Timer '+snum+' has not been started.'
print,' Do timer, /start first.'
return
endif
if t2(num) eq '' then begin
print,' Error: Timer '+snum+$
' must be stopped before elapsed time is available.'
print,' Do timer, /stop, /print'
return
endif
c = 1
if not keyword_set(cmt) then begin
print,' Timer '+snum+' started: '+t1(num)
print,' Timer '+snum+' stopped: '+t2(num)
print,' Elapsed time: ',strsec(dtc(num))+' ('+$
strtrim(fix(dtc(num)),2)+' sec)'
endif else begin
print,cmt+' elapsed time: ',strsec(dtc(num))+' ('+$
strtrim(long(dtc(num)),2)+' sec)'
endelse
endif

if c ne 1 then goto, hh

return
end
--
Stephen C Strebel / SKI TO DIE
stl@maz.sma.ch / and
Swiss Meteorological Institute, Zuerich / LIVE TO TELL ABOUT IT
01 256 93 85 / (and pray for snow)
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: seismic variable area plot
Next Topic: double integration in IDL....

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 19:16:05 PDT 2025

Total time taken to generate the page: 0.00530 seconds