Measuring Sitecore performance with HighResTimer

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();
    // execute the code to be timed.
    // 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:

About briancaos

Developer at Pentia A/S since 2003. Have developed Web Applications using Sitecore Since Sitecore 4.1.
This entry was posted in General .NET, Sitecore 4, Sitecore 5, Sitecore 6, Sitecore 7, Sitecore 8 and tagged , , . Bookmark the permalink.

2 Responses to Measuring Sitecore performance with HighResTimer

  1. Pingback: Sitecore Measure Pipeline performance and profile processors | Brian Pedersen's Sitecore and .NET Blog

  2. Pingback: Which of my old Sitecore posts are still valid in Sitecore 9? | Brian Pedersen's Sitecore and .NET Blog

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.