Re: idl speed question [message #65624] |
Sat, 14 March 2009 15:28  |
Michael Galloy
Messages: 1114 Registered: April 2006
|
Senior Member |
|
|
oxfordenergyservices@googlemail.com wrote:
> I have the following strange result
>
> a=double(1.0)
> for i=0,10000 do begin
> for j=0,10000 do begin
> a=a+1.0
> endfor
> endfor
>
> takes 13 seconds whereas
>
> a=double(1.0)
> b=double(1.0)
> c=double(1.0)
> d=double(1.0)
> e=double(1.0)
> for i=0,10000 do begin
> for j=0,10000 do begin
> a=a+1.0
> b=b+1.0
> c=c+1.0
> d=d+1.0
> e=e+1.0
> endfor
> endfor
>
> takes 60 seconds? I thought the overhead with IDL was in the loops
> rather than the computing?
The real killer for speed is number of statements (each one has to be be
interpreted). Loops are bad only because they could execute a statement
a possibly large number of times. So in your example, the first case has
10001 * 10001 statements while the second has 5 * 10001 * 10001
statements. So if the statements are doing the same amount of work, one
would expect the second to take about 5 times more time.
The conclusion: try to do more work per statement.
Mike
--
www.michaelgalloy.com
Associate Research Scientist
Tech-X Corporation
|
|
|