C#: Create Stopwatch Timer to Track Elapsed Time

2/11/2015 12:21:56 AM

Create a stopwatch timer to determine elapsed time. This can be very useful when testing performance of functions and determining bottle necks.

var stopwatch = new System.Diagnostics.Stopwatch();

//start the watch
stopwatch.Start();

//do something

//stop the watch
stopwatch.Stop();

//get total elapsed time
double ellapsedSeconds = stopwatch.Elapsed.TotalSeconds;