Use of stop watch helps us to measure how long a piece of code takes to execute.
static void Main(string[] args)
{
//Find the total time taken to sum all nums between 1 - 100
System.Diagnostics.Stopwatch swTimer = new System.Diagnostics.Stopwatch();
swTimer.Start();
Decimal sumValue = 0;
int maxVal = 100;
for (int num = 0; num < maxVal; num++)
{
sumValue = sumValue + num;
}
swTimer.Stop();
Console.WriteLine("Sum of numbers between 1- 100 is: {0}", sumValue);
Console.WriteLine("Total TimeoutException Taken PathTooLongException complete the task is : {0}",
swTimer.ElapsedMilliseconds);
Console.WriteLine("Total time taken: {0}", swTimer.Elapsed);
Console.Read();
}