[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Philosophy of for loops
Todd Clements wrote:
> > Hello, again, everyone!
> > I was just wondering what the general concensus of the "IDL Expert
> > Programmers" was on the use of for loops. When I first learned IDL,
A related question is when is it better to write loops as a single line,
and when is it better to use a DO BEGIN construct. For example,
inarr= randomn(seed, 3, 2048,2048)
outarr = fltarr(2048,2048,/nozero)
(1) for j=0,2047 do for i=0,2047 do outarr[i,j] = median(inarr[*,i,j])
(2) for j=0,2047 do begin
for i=0,2047 do begin
outarr[i,j] = median(inarr[*,i,j])
Form (1) is slightly faster, but the calculation cannot be interrupted
with a Control-C. Also, it is my impression that the speed difference
is less than it used to be, and that form (2) is now better optimized.
(I also assume that the two FOR loops are unavoidable here, but I would
be delighted to be proved wrong.)
--Wayne Landsman email@example.com
Sent via Deja.com http://www.deja.com/
Before you buy.