StopWatchUtil.cs 511 B

1234567891011121314151617181920212223242526
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace Ips.Library.Basic
  8. {
  9. public static class StopWatchUtil
  10. {
  11. public static TimeSpan Run(Action act)
  12. {
  13. var sw = Stopwatch.StartNew();
  14. try
  15. {
  16. act();
  17. }
  18. finally
  19. {
  20. sw.Stop();
  21. }
  22. return sw.Elapsed;
  23. }
  24. }
  25. }