Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static Action<int> CheckDuration(Action action)
- private static Action<int> CheckDuration<T>(Action<T> action, T arg)
- private static Action<int> CheckDuration<T, U>(
- Action<T, U> action, T arg1, U arg2)
- private static Action<int> CheckDuration<params T>(
- Action<params T> action, params T arg)
- public static class MethodTimer
- {
- public static long Run(Action action)
- {
- var sw = System.Diagnostics.Stopwatch.StartNew();
- action();
- sw.Stop();
- return sw.ElapsedMilliseconds;
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- long time = MethodTimer.Run(() => File.Open(@"c:test.txt",
- FileMode.CreateNew));
- Console.WriteLine(time);
- Console.ReadLine();
- }
- }
- Action act = () => File.Open(@"c:test.txt", FileMode.CreateNew);
- time=act.Time();
- public static class MethodTimer
- {
- public static long Time(this Action action)
- {
- var sw = System.Diagnostics.Stopwatch.StartNew();
- action();
- sw.Stop();
- return sw.ElapsedMilliseconds;
- }
- }
- MethodTimer.Time(()=> File.Open("",FileMode.Open);
- MethodTimer.Time(()=> myObject.TestMethod(123,1231,"another param"));
- Action<int> CheckDuration<T>(Action<T> action, params T[] args)
- where T : ISupportCheckDuration
Add Comment
Please, Sign In to add comment