locked
Time in Milliseconds or Microseconds, How ??!! RRS feed

  • Question

  • User1931228377 posted
    Hi; Q: How to computer the interval time from Starting block until its finish? For example, How to compute the time (in Millisecond or Microsecond) for execuation a serting block (Sortign or Searching Algorithm for example)? NOTE: Time must be in Millisecond or Microsecond, NOT in Second!! Thanks in advance!?
    Friday, September 26, 2003 4:14 AM

All replies

  • User462427678 posted
    You can use the DateTime class. Date.Now will give you the current time as an instance of that class. From there, you can call Date.Now.Milisecond() or Date.Now.Secon() or whatever you should need. Hope this helps, John
    Friday, September 26, 2003 5:37 AM
  • User2019981500 posted

     Hi just use below code to achive it

     private void btnGetExecutionTime_Click(object sender, EventArgs e)
    
            {
    
     
    
                //First Create the instance of Stopwatch Class
    
    
                Stopwatch sw = new Stopwatch();
    
                
    
    
                // Start The StopWatch ...From 000
    
    
                sw.Start(); 
    
                for (int i = 0; i <= 1000; i++)
    
                {
    
     
    
                }
    
                //Stop the Timer
    
    
                sw.Stop();
    
     
    
                
    
    
    //Writing Execution Time in label 
    
    
    string ExecutionTimeTaken = string.Format("Minutes :{0}\nSeconds :{1}\n Mili seconds :{2}",sw.Elapsed.Minutes,sw.Elapsed.Seconds,sw.Elapsed.TotalMilliseconds);
    
     
    
                label1.Text = ExecutionTimeTaken;
    
     
    
            }
    
    
    


     

    Regards

     

    Friday, January 22, 2010 1:30 AM