[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Philosophy of for loops
landsman@my-deja.com writes:
> (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])
> endfor
> endfor
>
> 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 hadn't realized these were different! My choice between the two
forms usually revolves around stylistic concerns, i.e., does the thing
fit on the line. My guess is that form (2) is a little slower
*because* it is doing the keyboard checking. I have some roundabout
evidence that this is true.
Craig
--
--------------------------------------------------------------------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
--------------------------------------------------------------------------