zoukankan      html  css  js  c++  java
  • C# 计时器

    有时候我们会需要计算某段代码运行的时间
    比如一个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();

  • 相关阅读:
    12
    11
    10
    9
    8
    7
    6
    5
    4
    3
  • 原文地址:https://www.cnblogs.com/zhangzhiping35/p/10723489.html
Copyright © 2011-2022 走看看