Measures the time taken to add some numbers : TimeSpan : Date Time C# Examples


C# Examples » Date Time » TimeSpan »

 

Measures the time taken to add some numbers









    
using  System;

class  MainClass
{

    public  static  void  Main()
    {
        DateTime  start  =  DateTime.Now;

        long  total  =  0;
        for  (int  count  =  0;  count  <  1000000;  count++)
        {
            total  +=  count;
        }

        TimeSpan  timeTaken  =  DateTime.Now  -  start;

        Console.WriteLine("Milliseconds  =  "  +  timeTaken.Milliseconds);
        Console.WriteLine("total  =  "  +  total);
    }
}
    
   
  
   



Output

Milliseconds = 0
total = 499999500000


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Date Time
» TimeSpan