Introduction
The .NET Stopwatch class is nothing new to .NET (it’s been around since version 2.0) but it may be one of those classes you weren’t aware of (I wasn’t aware of it and I’ve been programming .NET since 1.1!) It is very useful when you want to do some performance testing in your code or to get timings for whatever reason.
The Stopwatch Class
Quick facts:
Examples
The classic example simply creates an instance of the Stopwatch class, calls the Start() method, does the work and finally calls the Stop() method.
Stopwatch sw = new Stopwatch();
sw.Start();
// Do some work...
Thread.Sleep(2155);
sw.Stop();
Console.WriteLine("Elapsed time to do some work: {0}", sw.Elapsed.ToString());
Here is the output:

You can also instantiate a Stopwatch class using the StartNew() static method of the Stopwatch class. This method creates a new Stopwatch instance, sets the elapsed time property to zero and starts the watch.
Stopwatch sw = Stopwatch.StartNew();
// Do some work...
Thread.Sleep(2155);
sw.Stop();
Console.WriteLine("Elapsed time to do some work: {0}", sw.Elapsed.ToString());
The output of course is the same as the previous example.
If you need to know if the stopwatch is ticking, use the IsRunning property.
Conclusion
The Stopwatch class is a useful tool to have when you want to do some simple performance testing in your code. It’s easy to understand and code.