Stack Exchange Discussion

Aim to optimize when you have measured before and after improvement, rather than introducing complexity for no reason.

Also note this isn’t invitation to write O(n^3) code on non-trivial data sets.