I need to measure the execution of many different methods within the context of an application.
.NET of course has the Stopwatch class which allows one to easily time a section of code with it's .Start() and .Stop() methods.
However, use of the Stopwatch class in its normal manner requires me to decorate every method with an instance of a Stopwatch object and calls to it's .Start() and .Stop() methods.
I need to use Stopwatch functionality on literally hundreds of methods and do not want to pollute every method with this code. I would also like to have the ability to turn timing on and off.
Is there a simple way I can implement a generic timing solution within my own code? If so, how? Code profilers do it, so I think it must be possible.