Possible Duplicate:
Wrapping StopWatch timing with a delegate or lambda?
Hi,
Each time I want to check elapsed time for given method I have to do :
StopWatch sw = new StopWatch()
sw.Start();
MyMethod();
sw.Stop();
var result = sw.Elapsed.TotalMiliseconds;
It's not comfortable, I would like to have method like:
result = CheckTimeElapsed(MyMethod);
How to write method CheckTimeElapsed?
I don't know how to declare such delegate which may have any number of arguments.
For example function which I want to measue may have argument int
result = CheckTimeElapsed(MySecondMethod(10));
Thanks for help