.net中的两种计时方法

	    //秒表方法一:
            Stopwatch sw = new Stopwatch();
            sw.Start();
            for (int i = 0; i < 10000; i++)
            {

            }
            sw.Stop();
            MessageBox.Show(sw.Elapsed.TotalMilliseconds.ToString());

            //当前时间减去开始时间方法二:
            DateTime begintime = DateTime.Now;
            for (int i = 0; i < 10000; i++)
            {

            }
            TimeSpan ts = DateTime.Now.Subtract(begintime);
            MessageBox.Show(ts.TotalMilliseconds.ToString());

你可能感兴趣的:(.net)