Skip to content
galkahana edited this page Sep 14, 2010 · 2 revisions

For the sake of performance testing, either of the library functionality or your own code you can use the performance counters implementation of the library.

Two classes implement performance counters functionality: Timer and TimersRegistry.

The Timer class implements the ability to time a certain duration. The class has 3 important member functions:

  1. StartMeasure – starts the timer.
  2. StopMeasureAndAccumulate – stops the timer and accumulate the duration from the “StartMeasure” call
  3. GetTotalMiliSeconds – returns the total measure of all StartMeasureStopMeasure pairs.

Using the timer class is easy:

Timer timer;
timer.StartMeasure();
// Sleep(5);
timer.StopMeasureAndAccumulate();
TRACE_LOG("Number of seconds passed = %ld",(long)timer.GetTotalMiliSeconds());

The above code starts the timer, waits for 5 seconds, and then stops its measurement, later it traces the total waited time to the log.

The TimersRegistry class implements an easy method of Timing various code locations. Its interface is similar to the Timer class, however it also adds a string parameter to each call. This allows you to name various timers and control them through that name. The implementation of the class holds a collection of timers, each identified by a string.
The TimersRegistry class also has 3 other methods:

  1. ReleaseAll – releases all timers currently in the registry.
  2. TraceAll – traces all timers to the log.
  3. TraceAndReleaseAll – both traces the timers to the log and releases them.

For a complete example of using the TimersRegistry class see TimerTest.

Clone this wiki locally