White Box Testing
Test your code
   Home      TestPattern-PerformancePatterns
Author -  Marc Clifton
Marc is the creator of two open source projets, MyXaml, a declarative (XML) instantiation engine and the Advanced Unit Testing framework, and Interacx, a commercial n-tier RAD application suite.  Visit his website, www.marcclifton.com, where you will find many of his articles and his blog.
Marc lives in Philmont, NY.


Performance Patterns

Unit testing should not just be concerned with function but also with form.  How efficiently does the code under test perform its function?  How fast?  How much memory does it use?  Does it trade off data insertion for data retrieval effectively?  Does it free up resources correctly?  These are all things that are under the purview of unit testing.  By including performance patterns in the unit test, the implementer has a goal to reach, which results in better code, a better application, and a happier customer.

The Performance-Test Pattern

The basic types of performance that can be measured are:

  • Memory usage (physical, cache, virtual)
  • Resource (handle) utilization
  • Disk utilization (physical, cache)
  • Algorithm Performance (insertion, retrieval, indexing, and operation)

Note that some languages and operating systems make this information difficult to retrieve.  For example, the C# language with its garbage collection is rather difficult to work with in regards to measuring memory utilization.  Also, in order to achieve meaningful metrics, this pattern must often be used in conjunction with the Simple-Test-Data pattern so that the metric can measure an entire dataset.  Note that just-in-time compilation makes performance measurements difficult, as do environments that are naturally unstable, most notably networks.  I discuss the issue of performance and memory instrumentation in my fourth article in a series on advanced unit testing found at http://www.codeproject.com/csharp/autp4.asp.