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);  

相关文章:

  • 2022-01-26
  • 2022-01-23
  • 2021-12-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-23
猜你喜欢
  • 2021-05-23
  • 2022-01-13
  • 2022-12-23
  • 2021-07-08
  • 2021-09-22
  • 2022-12-23
相关资源
相似解决方案