用法如下:
System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();//初始化一个对象 watch.Start();//开始计时 //计时代码 StringBuilder sb = new StringBuilder(2000); for (int i = 0; i < 10000000; i++) { sb.Append(i.ToString()); } watch.Stop();//停止计时 System.Diagnostics.Debug.WriteLine("耗时:" + watch.Elapsed);//输出时间 毫秒
时间: 2024-12-19 17:51:47