你有四個選項中,至少。
小test project我沒有...
日期時間檢查
DateTime begin = DateTime.UtcNow;
//what you want to control...
DateTime end = DateTime.UtcNow;
Console.WriteLine("DateTime.UtcNow measured time: {0} ms", (end - begin).TotalMilliseconds);
進度檢查
using System.Diagnostics;
...
TimeSpan begin = Process.GetCurrentProcess().TotalProcessorTime;
//what you want to control...
TimeSpan end = Process.GetCurrentProcess().TotalProcessorTime;
Console.WriteLine("Process.TotalProcessor measured time: {0} ms", (end - begin).TotalMilliseconds);
秒錶檢查
using System.Diagnostics;
...
Stopwatch watch = new Stopwatch();
watch.Start();
//what you want to control...
watch.Stop();
Console.WriteLine("Stopwatch measured time: {0} ms", watch.ElapsedMilliseconds);
TickCounter檢查
int start = Environment.TickCount;
//what you want to control...
int duration = Environment.TickCount - start;
Console.WriteLine("TickCount measured time: {0} ms", duration);
[秒錶](http://msdn.microsoft.com/en-我們/庫/ system.diagnostics.stopwatch%28V = vs.110%29.aspx) – 2014-10-27 13:37:15