Guest User

Untitled

a guest
Jun 20th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. private static Action<int> CheckDuration(Action action)
  2. private static Action<int> CheckDuration<T>(Action<T> action, T arg)
  3.  
  4. private static Action<int> CheckDuration<T, U>(
  5. Action<T, U> action, T arg1, U arg2)
  6.  
  7. private static Action<int> CheckDuration<params T>(
  8. Action<params T> action, params T arg)
  9.  
  10. public static class MethodTimer
  11. {
  12. public static long Run(Action action)
  13. {
  14. var sw = System.Diagnostics.Stopwatch.StartNew();
  15. action();
  16. sw.Stop();
  17. return sw.ElapsedMilliseconds;
  18. }
  19. }
  20. class Program
  21. {
  22. static void Main(string[] args)
  23. {
  24. long time = MethodTimer.Run(() => File.Open(@"c:test.txt",
  25. FileMode.CreateNew));
  26. Console.WriteLine(time);
  27. Console.ReadLine();
  28. }
  29. }
  30.  
  31. Action act = () => File.Open(@"c:test.txt", FileMode.CreateNew);
  32. time=act.Time();
  33.  
  34. public static class MethodTimer
  35. {
  36. public static long Time(this Action action)
  37. {
  38. var sw = System.Diagnostics.Stopwatch.StartNew();
  39. action();
  40. sw.Stop();
  41. return sw.ElapsedMilliseconds;
  42. }
  43. }
  44.  
  45. MethodTimer.Time(()=> File.Open("",FileMode.Open);
  46. MethodTimer.Time(()=> myObject.TestMethod(123,1231,"another param"));
  47.  
  48. Action<int> CheckDuration<T>(Action<T> action, params T[] args)
  49. where T : ISupportCheckDuration
Add Comment
Please, Sign In to add comment