Calculate the execution time of a method in C#To calculate the execution time in C# we can use
System.Diagnostics.Stopwatch.StartNew()which initializes a new Stopwatch instance, sets the elapsed time property to zero, and starts measuring elapsed time, and stop Stopwatch object by using method
Stop();and finally return elapsed time in milliseconds using property
ExampleIn below example we are using thread sleep to stop execution of application for 3000 millisconds.
Elapsed time: 3006