In my code, I have to access variables in a struct about 1000 times. I was wondering whether it is faster to copy the struct to a local variable first.
But I always thought a.b is faster than a->b, because a->b requires the program to access the memory twice.
I always thought this too. Deferencing a pointer (->) requires indirection which means reading a pointer, then reading a value from that pointer... whereas the (.) operator doesn't require dereferencing so it can just read the value directly (or at worst with indexing).
Although micromanagements like these are generally not worth your time. Leave this kind of thing up to the compiler. A lot of times the compiler will optimize stuff like this by keeping a pointer that's constantly being dereferenced in a register so that dereferences are quick. Often, you might even make the program slower by trying to make premature optimizations like this.
Ultimately, though, it all depends on the compiler. What optimizations it does and where. If you're really that concerned (which you shouldn't be unless you're experiencing noticable slowdown), run a profiler with and without your ideas for optimizations and compare the results. That's really the only way to know for sure -- and even then results may vary if people try to compile (or even run!) your program on a different machine.