Paul Hsieh‘s Programming optimization: techniques, examples and discussion is a pretty good reading material, since most likely there’s something you didn’t know about or didn’t consider when optimizing your code. The section on misconceptions is probably the most informative:
Globals are faster than locals – Most modern C compilers will alias local variables to your CPUs register’s or SRAM. Furthermore, if all variables in a given scope are local, then an optimizing compiler, can forgo maintaining the variable outside the scope, and therefore has more simplification optimization opportunities than with globals. So, in fact, you should find the opposite tends to be true more of the time.
