1. 程式人生 > >計算方法執行時間

計算方法執行時間

system action on() blog class 幫助 cos clas nbsp

/// <summary>
    /// 方法幫助類
    /// </summary>
    public class ActionHelper
    {
        /// <summary>
        /// 統一計算執行時間
        /// </summary>
        /// <param name="action">執行方法</param>
        /// <returns></returns>
        public static int ComputeMethodCostMilliseconds(Action action)
        {
            
var stopwatch = new System.Diagnostics.Stopwatch(); stopwatch.Start(); // 開始監視 action(); stopwatch.Stop(); // 停止監視 var timeSpan = stopwatch.Elapsed; // 獲取總時間 return (int)timeSpan.TotalMilliseconds; } }

計算方法執行時間