<< Back to Blog

11 OCTOBER 2019

.NET Core: Using Timer to record execution time of code block

using System.Diagnostics
...
var timer = new Stopwatch();
timer.Start();

// Do something you want to profile

timer.Stop();
var elapsedMs = timer.ElapsedMilliseconds;