February 14, 2011

Time measurement with Stopwatch

When I need to measure how long some action take I use Stopwatch class. It's in System.Diagnostics.
Here's sample:

Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();

// action I want to measure

stopwatch.Stop();

Or just

Stopwatch stopwatch = Stopwatch.StartNew();

// action I want to measure

stopwatch.Stop();

It's more precise than using DateTime.

No comments:

Post a Comment