As Scale Developers, we’re often required to verify that our systems meet their performance requirements. The best practice is to instrument your application using performance counters. But sometimes you ‘inherit’ an application that is already ‘instrumented’ with calls to the Stopwatch class. Hopefully this post will help you deal with this class in a more informed way.
This class basically provides a wrapper for the QueryPerformanceCounter and QueryPerformanceFrequency functions. Many of you probably already knew this but what you might not have known is that these functions used much different measuring between Windows 5 and Windows 6.
Under Windows 5 these functions use rdtsc for its measurements. On W5 this is pretty fast at only 100 cycles for each start and each stop. However, if you’ve used this before, you know that its not terribly accurate and can fail on multi processor systems. For example if a start occurs on one proc and a stop occurs on another processor at the same or earlier time, then the function will return a zero timespan.
Enter Windows 6. It uses a much more accurate type of measurement: hpat (couldn’t find the link). However, if you use it, you will notice an immediate significant performance degradation! The reason is that this method is much more expensive: 700ns for each call! Holy cow!
So in summary, just because you have a way to measure your process, make sure you understand it and its ramifications!!!
Happy Coding!