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