Many thanks to John for commenting on my Performance Tuning article. I’d just like to quote a snippet of what John has to say:
“After all there’s no point optimising code that doesn’t actually work correctly”
It reminded me of something obvious I forgot to mention in my previous articles: another of the “sins” I have seen often seen programmers committing is trying to get code to run fast at the same time as they first writing code. Also, these programmers seemed (usually) to get themselves into a tangle, which is hardly surprising, because they make things difficult for themselves by trying to solve two problems at once. They are trying to both get their code working (in an operational sense), and speed it up, both at the same time. This ties in with what I said in my Performance Requirements article: programmers trying to optimise code while they first write it are trying to solve a performance problem, while having no idea if this problem actually exists or not.
Therefore, the correct approach is to first get code working operationally by using the simplest implementation possible. This should be quite quick (relatively speaking) and must include the writing of test cases. Then, performance can be measured and, if necessary, the code speeded up. Naturally the test cases must be run against the changes, thus verifying that functionality has not been broken.