Re: An optimisation question [message #79709 is a reply to message #79708] |
Tue, 27 March 2012 15:45   |
Matt Francis
Messages: 94 Registered: May 2010
|
Member |
|
|
Okay, just probing my original approach further to understand what is
going on and I'm going completely insane. Have a look at this test
code:
function do_3d,arr,lat,lon,indx
temp = reform(arr[indx,*,*])
return,temp[lat,lon]
end
function do_2d_first,arr,lat,lon
return,arr[lat,lon]
end
function do_2d_second,arr,lat,lon
return,arr[lat,lon]
end
pro crazy_idl
lat = intarr(10000)
lon = intarr(10000)
arr3d = fltarr(10,1000,1000)
arr2d = fltarr(1000,1000)
for i=0,100 do begin
res3d = do_3d(arr3d,lat,lon,0)
res2d = do_2d_first(arr2d,lat,lon)
res2d = do_2d_second(reform(arr3d[0,*,*]),lat,lon)
endfor
end
The '3d' version first uses REFORM to obtain a 2d matrix and then does
the same thing as the '2d' version. The second call to the 2d version
does the REFORM command before sending the array to the subroutine.
All three approaches are essentially the same, apart from some minor
overhead coming from using REFORM. Well, no. Apparently these are all
very different! Check out the profiler report:
Module Type Count Only(s) Avg.(s) Time(s) Avg.(s)
CRAZY_IDL (U) 1 0.967564 0.967564 1.963462 1.963462
DO_2D_FIRST (U) 101 0.003964 0.000039 0.003964 0.000039
DO_2D_SECOND (U) 101 0.004870 0.000048 0.004870 0.000048
DO_3D (U) 101 0.973172 0.009635 0.973531 0.009639
FLTARR (S) 2 0.013167 0.006583 0.013167 0.006583
INTARR (S) 2 0.000012 0.000006 0.000012 0.000006
PROFILER (S) 2 1.007490 0.503745 1.007490 0.503745
REFORM (S) 202 0.000711 0.000004 0.000711 0.000004
What the hell?? One of either me or IDL is doing something completely
screwy and frankly I don't care which it is, I just want to understand
what is going on. I guess the other possibility is that the profiler
is getting this completely wrong a misreporting the times in some
weird way?
|
|
|