C#之时间统计

  1. DateTime beforDT = System.DateTime.Now;    
  2.   
  3.     //耗时巨大的代码  
  4.       
  5.     DateTime afterDT = System.DateTime.Now;  
  6.     TimeSpan ts = afterDT.Subtract(beforDT);  
  7.     Console.WriteLine("DateTime总共花费{0}ms.", ts.TotalMilliseconds);  
  1.  Stopwatch sw = new Stopwatch();  
  2.     sw.Start();  
  3.     
  4.     //耗时巨大的代码  
  5.       
  6.     sw.Stop();  
  7.     TimeSpan ts2 = sw.Elapsed;  
  8.     Console.WriteLine("Stopwatch总共花费{0}ms.", ts2.TotalMilliseconds);  
原文地址:https://www.cnblogs.com/huangshiyu13/p/5645494.html