Tag Archives: StopWatch

Use the Stopwatch class to time a program in C#

To measure elapsed time, you can save the current time with DateTime.Now and then compare it to a later time to see how much time has elapsed. The Stopwatch class in the System.Diagnostics namespace makes this a bit easier. It’s … Continue reading

Posted in performance | Tagged , , , , , , , , , | Leave a comment

Make a stopwatch in C#

This program is a simple stopwatch. When you click the Start button, the program changes the button’s caption to Stop and starts a Timer. As the stopwatch Timer runs, the program displays the elapsed time. Click the Stop button to … Continue reading

Posted in internationalization, miscellany, strings | Tagged , , , , , , , , , , , , , | Leave a comment

See how much time a checked block takes in C#

The post Control overflow behavior with checked and unchecked in C# explains how to use checked blocks to watch for integer overflow. If you don’t use checked, the program may encounter integer overflow errors without you knowing it. It seems … Continue reading

Posted in calculations, mathematics, performance, syntax | Tagged , , , , , , , , , , , , , , , | Leave a comment

Measure elapsed time in C#

For most tasks, you can measure elapsed time with the Stopwatch or DateTime classes. To use the Stopwatch class, create a Stopwatch object. Use its Start and Stop methods to start and stop it. If you use Start after stopping … Continue reading

Posted in performance, system | Tagged , , , , , , , , , , , | Leave a comment