Freigeben über


Use "Stopwatch" class to calculate the execution time

Although this class is not famous, it does a great job to calculate the execution time. Usually, the execution time of a code block is calculated by setting a start and stop variable (DateTime) just before and after the code block and then calculating the difference between "start" and "stop" variable by substracting the "start" from the "stop". Yes, this does the work but why using that when you have a Stopwatch class which does exactly what is needed? I will not provide a sample code here because the related MSDN article is pretty clear and has a good sample code snippet, which explains the basics. Please see https://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.aspx for the details.

Applies to:

.NET 2.0
.NET 3.0
.NET 3.5
.NET 4.0

--
AMB

Comments

  • Anonymous
    January 05, 2012
    Thanks Dude!!! Great Work!!!