有时候我们会需要计算某段代码运行的时间

比如一个sql查询,记录一段代码所花费的时间等等
代码如下:

System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
            watch.Start();//开始计时
       
            string str = "";
            for (int i = 0; i < 100000; i++)
            {
                str += i.ToString();
            }

            watch.Stop();//停止计时

            Console.WriteLine("耗时:" + (watch.ElapsedMilliseconds));//输出时间 毫秒

            Console.ReadKey();
View Code

相关文章:

  • 2022-12-23
  • 2021-11-08
  • 2021-04-16
  • 2021-09-22
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-08-19
  • 2022-01-28
  • 2021-05-20
  • 2021-10-29
相关资源
相似解决方案