static void SubTest()
{
    Stopwatch sw = new Stopwatch();
    sw.Start();
  
    //耗时巨大的代码
    
    sw.Stop();
    TimeSpan ts2 = sw.Elapsed;
    Console.WriteLine("Stopwatch总共花费{0}ms.", ts2.TotalMilliseconds);
}
第一种方法利用System.DateTime.Now
static void SubTest()
{
    DateTime beforDT = System.DateTime.Now;  

    //耗时巨大的代码
    
    DateTime afterDT = System.DateTime.Now;
    TimeSpan ts = afterDT.Subtract(beforDT);
    Console.WriteLine("DateTime总共花费{0}ms.", ts.TotalMilliseconds);
}

// 出处 忘记了。。。

相关文章:

  • 2021-05-04
  • 2021-06-07
  • 2021-10-11
  • 2021-09-10
  • 2021-11-15
  • 2022-12-23
猜你喜欢
  • 2021-09-29
  • 2021-11-02
  • 2021-11-15
  • 2021-10-28
  • 2022-12-23
  • 2022-12-23
  • 2021-12-21
相关资源
相似解决方案