Creating an Instance of a Stopwatch

suggest change

A Stopwatch instance can measure elapsed time over several intervals with the total elapsed time being all individual intervals added together. This gives a reliable method of measuring elapsed time between two or more events.

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

double d = 0;
for (int i = 0; i < 1000 * 1000 * 1000; i++)
{
    d += 1;
}

stopWatch.Stop();
Console.WriteLine("Time elapsed: {0:hh\\:mm\\:ss\\.fffffff}", stopWatch.Elapsed);

Stopwach is in System.Diagnostics so you need to add using System.Diagnostics; to your file.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents