You are given a heap of code in your favorite language which combines to form a rather complicated application. It runs rather slowly, and your boss has asked you to optimize it. What are the steps you follow to most efficiently optimize the code?
What strategies have you found to be unsuccessful when optimizing code?
Re-writes: At what point do you decide to stop optimizing and say "This is as fast as it'll get without a complete re-write." In what cases would you advocate a simple complete re-write anyway? How would you go about designing it?
Profile before attempting any optimisation.
9 times out of 10, the time won't be consumed where you might guess it is.
The usual unsuccessful strategy is micro-optimisation, when what is actually required is the appropriate algorithm.
Obligatory Donald Knuth quote:
"We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil"