1. 程式人生 > >C#監控代碼執行效率

C#監控代碼執行效率

light 運行時 測量 pan 獲取 min mes csharp stopwatch

System.Diagnostics.Stopwatch stopwatch = new Stopwatch();
stopwatch.Start(); // 開始監視代碼運行時間

//需要監測的代碼

stopwatch.Stop(); // 停止監視
TimeSpan timespan = stopwatch.Elapsed; // 獲取當前實例測量得出的總時間

string hours = timespan.TotalHours.ToString("#0.00000000 "); // 總小時
string minutes = timespan.TotalMinutes.ToString("#0.00000000 "); // 總分鐘
string seconds = timespan.TotalSeconds.ToString("#0.00000000 "); // 總秒數
string milliseconds = timespan.TotalMilliseconds.ToString("#0.00000000 "); // 總毫秒數

  

C#監控代碼執行效率