StopwatchExtension.cs 536 B

1234567891011121314151617181920212223
  1. using System;
  2. using System.Diagnostics;
  3. namespace Masuit.Tools.Systems
  4. {
  5. /// <summary>
  6. /// stopwatch扩展
  7. /// </summary>
  8. public static class StopwatchExtension
  9. {
  10. /// <summary>
  11. /// 检测方法执行时间
  12. /// </summary>
  13. /// <param name="action"></param>
  14. /// <returns></returns>
  15. public static double Execute(Action action)
  16. {
  17. Stopwatch sw = Stopwatch.StartNew();
  18. action();
  19. return sw.ElapsedMilliseconds;
  20. }
  21. }
  22. }