As pasztorpisti said, this is not an area you should bother looking at for optimizations - these savings are (generally) made by changing the approach to a problem, _not_ by changing the syntax you use to access a particular piece of data.
Sometimes cache-locality can play a part, which can dictate the amount by which a loop can be un-rolled before the benefit of doing so is lost.
That said, they're not quite the same, as can be shown with a small snippet of code.
First, the results:
Run 1:
Time elapsed to complete 500000000 iterations: 3.561095
Time elapsed to complete 500000000 iterations: 3.797974
Dif = 0.236879s
Run 2:
Time elapsed to complete 500000000 iterations: 3.546631
Time elapsed to complete 500000000 iterations: 4.148972
Dif = 0.602341s
Run 3:
Time elapsed to complete 500000000 iterations: 2.312600
Time elapsed to complete 500000000 iterations: 2.926228
Dif = 0.613628s
Run 4:
Time elapsed to complete 500000000 iterations: 3.227201
Time elapsed to complete 500000000 iterations: 3.392681
Dif = 0.16548s
Next, the code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
LARGE_INTEGER clockFreq;
LARGE_INTEGER tStart, tEnd;
struct node
{
char name[20];
};
LARGE_INTEGER getTicks()
{
LARGE_INTEGER result;
QueryPerformanceCounter(&result);
return result;
}
double elapsedSecs(LARGE_INTEGER tStart, LARGE_INTEGER tEnd)
{
long ticksElapsed = tEnd.QuadPart - tStart.QuadPart;
double timePeriod = (double)ticksElapsed / (double)clockFreq.QuadPart;
return timePeriod;
}
int main(void)
{
struct node n1;
struct node* ptr;
long i, max = 500000000;
char *tmp;
QueryPerformanceFrequency(&clockFreq);
strcpy(n1.name, "HelloWorld!");
ptr = &n1;
tStart = getTicks();
for (i=0; i<max; i++)
{
tmp = ptr->name;
}
tEnd = getTicks();
printf("Time elapsed to complete %d iterations: %f\n", max, elapsedSecs(tStart, tEnd));
tStart = getTicks();
for (i=0; i<max; i++)
{
tmp = n1.name;
}
tEnd = getTicks();
printf("Time elapsed to complete %d iterations: %f\n", max, elapsedSecs(tStart, tEnd));
printf("%s\n", ptr->name);
printf("%s\n", n1.name);
return 0;
}
Finally, the qualification and testing environment:
While we can see that the times taken vary considerably over the course of the 4 runs, in each and every case the ptr->name access is faster. But before you celebrate, do realize that in each case we're doing 500 million iterations. Yet the time difference is only in the order of 15% of the total time.
So, the importance of saving 15% of next to nothing is.... you guessed it - even closer to nothing!
Windows task-switching (which is beyond your control) has a far,
far greater effect than the access method.
Test machine: i3 M220 @ 2.13 Ghz, 4GB, Win7 Home prem