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:
- Benchmarking, HighResTimer and string concatenation by Alex De Groot (old post)
- Sitecore performance optimization – Sitecore configurations, IIS configurations from Stackoverflow
- Sitecore poor database performance
- Improve Sitecore Membership provider performance 2-20 times
