# Sunday, December 14, 2003

Doing some performance testing on my current project showed me the evils of premature optimization and the need to test performance first before 'optimizing' the code.

A month ago when I started on the project there was no working deployed version of the application in an environment I could run tests against, so I did some code reviews and eyeballed areas of the architecture that might be slow.  The project uses BizTalk 2002 Orchestrations to process a SOAP message that is passed around as a string.  All of this manipulation was based around the XmlDocument DOM model, which had been slow and memory-hungry in previous projects, so I wrote some code to test the speed of different approaches to XML processing.  Using the XPathDocument and XPathNavigator turned out to be 70% faster. 

However, when I analysed the entire web service method only 6% of the call time was spent in these methods.  So even if we implemented the change it would only improve the overall performance of the web service call by about 4%.  This may or may not be worth it, but it highlighted to me the need to get real performance figures to test my assumptions about where the bottlenecks were in the code. As Donald Knuth says:

"We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil."