A time tested optimization pattern.
- First, make the code do what it is supposed to do. Do not try to optimize for size or speed yet. DoTheSimplestThingThatCouldPossiblyWork.
- Second, reduce redundancy. Refactoring common code to a common location is easier once the code works, harder after it has been optimized for performance. OnceAndOnlyOnce.
- Third, optimize execution time. ProfileBeforeOptimizing.
See also MakeItWorkMakeItRightMakeItFast. (Make It Small is basically a subset of Make It Right.)