Use of stop watch in c#

Madhu.b.rokkam
Posted by Madhu.b.rokkam under C# category on | Points: 40 | Views : 2956
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();
}

Comments or Responses

Login to post response