Martin McBride
Feb 12, 2022

This won't make your code run 2.5 times faster. It will make a loop that does nothing except access a single attribute run 2.5 times faster.

This is done at the cost of making your code longer and less readable, and with considerable scope for introducing bugs (for example if you modify the local variable then forget to copy it back to the attribute after the loop terminates).

Generally you shouldn't do this type of optimisation except in specific situations where it is likely to make a significant difference.

Martin McBride
Martin McBride

No responses yet