I've read a fair amount of stuff about efficiency of array indices vs. pointers, and how it doesn't really matter unless you're doing something a lot. However, I am doing this a lot.
The code in question has an array of structs. (Two different ones, for two different types actually, but whatever). Since my background is mostly in higher level languages, I defaulted to using a standard particles[i].whatever
format. However, I'm not sure if that's a good idea. For a single access, I know it doesn't matter much, but as it stands now, one of my two main functions calls particles[i].something
8 times, and boxes[boxnum].something
4 times per particle, per iteration.
Currently it takes roughly a second to do 5000 particles and 5000 iterations. This means that I'm dealing with these accesses upwards of [including the other function] 200 million times a second. At that frequency, every little bit matters (especially since I'll end up running this code on time on someone else's cluster).
So my question is if it's worth it to do something along the lines of using a pointer to the struct instead of the array access, if gcc will magically do that for me, or if it really doesn't matter.
Thanks ~~Zeb
EDIT: OK, so compiler magic means I shouldn't worry about it. Thanks.
You suggest a profiler, but I can't seem to make gprof tell me any finer-grained information than the time functions take... and I already know that. Is there anything that'll tell me that on a line-by-line basis?