Quantcast
Channel: Brian Pedersen's Sitecore and .NET Blog
Viewing all articles
Browse latest Browse all 286

Measuring Sitecore performance with HighResTimer

$
0
0

The HighResTimer is a Sitecore feature that has been around since Sitecore 4. It’s a simple timer that allows you to very precisely measure time in microseconds by using the underlying OS timers.

It is very easy to use:

public void MyMethod()
{
  // Initialize and start the timer:
  Sitecore.Diagnostics.HighResTimer ht = new Sitecore.Diagnostics.HighResTimer();
  ht.Start();
  try
  {
    // execute the code to be timed.
  }
  finally
  {
    // Dump the elapsed timespan to the log:
    Sitecore.Diagnostics.Log.Info("Time elapsed: " + ht.ElapsedTimeSpan.ToString(), this);
  }
}

The HighResTimer allows you to read the number of milliseconds or as I do in this example, read the time elapsed with a precision of 7 digits. The log line from the above example looks like this:

10112 12:25:28 INFO  Time elapsed: 00:00:00.0073862

More to read:



Viewing all articles
Browse latest Browse all 286

Trending Articles