<< Back to Blog

11 OCTOBER 2019

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

It can be useful to use a timer as a way of getting a rough gauge on how long a piece of code takes to execute.


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

// Do something you want to profile

var elapsedMs = timer.ElapsedMilliseconds;