C#中查看语句的执行时间--Stopwatch类

范例:

using System;
using System.Diagnostics;
using System.Threading;

class Program
{
    static void Main()
    {
	// Create new stopwatch
	Stopwatch stopwatch = new Stopwatch();

	// Begin timing
	stopwatch.Start();

	// Do something
	for (int i = 0; i < 1000; i++)
	{
	    Thread.Sleep(1);
	}

	// Stop timing
	stopwatch.Stop();

	// Write result
	Console.WriteLine("Time elapsed: {0}",
	    stopwatch.Elapsed);
    }
}

Output

Time elapsed: 00:00:01.0001477
posted on 2013-03-05 15:47  ltyfat  阅读(267)  评论(0编辑  收藏  举报