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:
Pingback: Sitecore Measure Pipeline performance and profile processors | Brian Pedersen's Sitecore and .NET Blog
Pingback: Which of my old Sitecore posts are still valid in Sitecore 9? | Brian Pedersen's Sitecore and .NET Blog