System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); //这里填写要执行的代码
sw.Stop(); Console.WriteLine("总运行时间:" + sw.Elapsed); Console.WriteLine("测量实例得出的总运行时间(毫秒为单位):" + sw.ElapsedMilliseconds);
double duration = (double)sw.ElapsedTicks / (double)System.Diagnostics.Stopwatch.Frequency * 1000; Console.WriteLine("测量实例得出的总运行时间(毫秒为单位):" + duration.ToString("N4"));
Console.WriteLine("总运行时间(计时器刻度标识):" + sw.ElapsedTicks); Console.WriteLine("计时器是否运行:" + sw.IsRunning.ToString());
|