Author: Dieter Buerssner
Date: 16:36:56 01/01/03
Go up one level in this thread
On January 01, 2003 at 11:50:58, Lieven Clarisse wrote:
>I know for instance that:
>
>ptr=&R[i];
>if((*ptr==3)||(*ptr==7)) {;}
>
>is faster then:
>
>if((R[i]==3)||(R[i]==7)) {;}
How did you test it? I checked compiler generated assembly in similar cases.
Typically, they are the same, using pointers or arrays. Sometimes arrays will be
faster.
gcc -O2 (at least some versions of gcc) optimized array indexed code exactly to
your pointer code, and thereby made the code *slower* on x86 (which has opcodes
for array indexing). I studied quite some optimization options and assembler
output of gcc for numerical code. Typically -O2 was slower than -O, and onme
reason was that gcc likes to see every array access as a pointer, and may need
one register more, because of this. The array access formulation looks more
readable to me, anyway. In reality, it is of course often much more subtle, and
microoptimizations are possible. I think, most of the time, they should be
omitted.
Regards,
Dieter
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.