title: How do I create a generic routine to time methods?
body: <p>I need to measure the execution of many different methods within the context of an application.</p>
  
  <p>.NET of course has the Stopwatch class which allows one to easily time a section of code with it's .Start() and .Stop() methods.</p>
  
  <p>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.</p>
  
  <p>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. </p>
  
  <p>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.</p>