Measure the code execution time using Stopwatch instance in C#

In C#, the System.Diagnostics namespace of System.Runtime.dll has the Stopwatch class which can be used to accurately measure the time taken for code execution.

Measure the code execution time using Stopwatch instance in C#:

A Stopwatch instance can be used to measure elapsed time for one interval or the total of elapsed time across multiple intervals. In the below example you can see how to use Stopwatch scenario where the Start method is called first, then eventually Stop method is called, and then Elapsed property is checked for the time taken to execute the piece of code.

The following example demonstrates how to use the Stopwatch class to determine the execution time for an application of a for loop.

– Article ends here –

Recommended:   How to list all the dependent windows services using C#
Share this:


Kiran is a Software engineer by profession and Enthusiastic blogger, love to write articles on computer technology and programming. Reach him at

We will be happy to hear your thoughts

Leave a reply

Shopping cart