Which is faster?

I'm trying to optimize my game engine's collision-checking code, and I decided that I would encapsulate it in a function. I wasn't sure if I should pass pointers or references because I didn't know if references were any faster than pointers. Plus, the way the game engine is designed, you have to dereference 2-3 times to get a variable.

So, my question is:

1
2
3
4
//is this
inst_point->object_index->collision_type;
//any faster than this?
inst_ref.object_index->collision_type;
The top is slightly slower in the normal case because you have to dereference the pointer. However, since the bottom one is using references, is is probably the same speed (since references are generally implemented as pointers).
Plus, the way the game engine is designed, you have to dereference 2-3 times to get a variable.
Maybe the design is incorrect (maybe you don't have the need to get that variable).
Instead of caring of such minimal optimisations, fix the design.
I agree totally with ne555. In the early days of IT computing, such optimization maybe valid concerns but at this current age, most hardware has improved leaps and bounds. Instead the current performance issues we are facing are due more to the design of the whole program.

I read somewhere, design of a program is like the blue-print for a building. If your blue-print is bad, I doubt the building is able to withstand the test of time. Likewise for IT programs, very often the design dictate a big portion on the performance issues.

Of cuz after say we have a *good* design and the performance issues still cropped up then maybe we can re-visit the good old days of optimizing our code further.
Topic archived. No new replies allowed.