Hi there,
I have some code that is called millions of times in succession, and naturally I want it to be as fast as possible. However, I have noticed something that is both cough interesting but above all very frustrating.
I have a file that contains structures thus:
Module Animal_hdr
Type stColours Integer*1, Pointer i1Colour(:) End Type stColours
Type stStripes Type(stColours), Pointer :: pstStripe(:, ð EndType stStripes
Type stZebras Type(stStripes), Pointer :: pstZebra(:, ð Integer*4 :: iOffsetLargeX, iOffsetLargeY EndType stZebras
End Module Animal_hdr
Now, the routine that is called millions of times has the following (and more) lines in it:
!! Passed Type(stZebras), INTENT(INOUT) :: pstZebraP
!! Locals Type(stStripes), Pointer :: ptrZebraL Type(stColours), Pointer :: ptrStripeL
ptrZebraL => pstZebraP%pstZebra(iyOffsetL + 1, ixOffsetL + 1)
ptrStripeL => ptrZebraL%pstStripe(iySmallIxL + 1, ixSmallIxL + 1)
and it takes around 124 seconds on my 520M Laptop to exectute 1M times.
However, if I change the above two lines for the single line:
ptrStripeL => pstZebraP%pstZebra(iyOffsetL + 1, ixOffsetL + 1) &
& %pstStripe(iySmallIxL + 1, ixSmallIxL + 1)
then it takes around 10 seconds to execute.
Not only that, if I try the trick in another place of this routine it actually slows things down, and so even though it is a mystery, I can't even follow a rule-of-thumb to get me by right now.
Any help much appreciated.
Marz
PS: I have written a small stand-alone project for the above.