The Stopwatch object is often used to measure how long things take. One quick thing to remember here is that it will take the time for everything you do between starting and stopping it, so make sure you only put the actual code you want to time between those.
using System.Diagnostics;
//...
void StopwatchUsingMethod()
{
//A: Setup and stuff you don't want timed
var timer = new Stopwatch();
timer.Start();
//B: Run stuff you want timed
timer.Stop();
TimeSpan timeTaken = timer.Elapsed;
string foo = "Time taken: " + timeTaken.ToString(@"m\:ss\.fff");
}
Foo will here show the minutes, seconds, and milliseconds it took to complete, though will show as wrong if it takes more than 59 minutes. Further information about TimeSpan can be found here: https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-timespan-format-strings
