Why the array index is faster than pointer? Isn\'t pointer supposed to be faster than array index?
** i used time.h clock_t to tested two functions, each loop 2 mil
Oops, on my 64-bit system results are quite different. I've got that this
int i;
for(i = 0; i < size; i++)
{
*(a+i) = 0;
}
is about 100 times !! slower than this
int i;
int * p = a;
for(i = 0; i < size; i++)
{
*(p++) = 0;
}
when compiling with -O3. This hints to me that somehow moving to next address is far easier to achieve for 64-bit cpu, than to calculate destination address from some offset. But i'm not sure.
EDIT:
This really has something related with 64-bit architecture because same code with same compile flags doesn't shows any real difference in performance on 32-bit system.