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


浙公网安备 33010602011771号