C#获取代码执行时间(精确到毫秒)

         private void Time(int i)
         {
            Stopwatch sw = new Stopwatch();
            sw.Start();
            Thread.Sleep(i);
            sw.Stop();
            Console.WriteLine(sw.ElapsedTicks / (decimal)Stopwatch.Frequency * 1000);
         }
   

 在main函数中调用Time(1000); 定时1000ms,

 控制台显示实际运行时间:999.9807566979519995073714676

posted @ 2014-05-19 09:17  Simon Lau  阅读(5214)  评论(0编辑  收藏  举报