title: Decorator for timeit.timeit method?
body: <p>I'm trying to write a simple time decorator to measure time taken by functions. However the code below is giving our recursion error. What's wrong with it?</p>
  
  <pre><code>import timeit
  
  def measure(func):
      def wrapper():
          func_name = func.__name__
          setup="from __main__ import {}".format(func_name)
          op_time = timeit.timeit('{}()'.format(func_name), number = 2, setup=setup)
          print(ot)
      return wrapper
  
  @measure
  def sample():
      return 10
  
  sample()
  </code></pre>
  
  <p>Output</p>
  
  <pre class="lang-none prettyprint-override"><code>RecursionError                            Traceback (most recent call last)
  &lt;ipython-input-61-e079e1bd7fba&gt; in &lt;module&gt;()
       15     return 10
       16
  ---&gt; 17 sample()
  
  &lt;ipython-input-61-e079e1bd7fba&gt; in wrapper()
        7         func_name = func.__name__
        8         setup="from __main__ import {}".format(func_name)
  ----&gt; 9         op_time = timeit.timeit('{}()'.format(func_name), number = 2, setup=setup)
       10         print(ot)
       11     return wrapper
  
  ~/anaconda3/lib/python3.6/timeit.py in timeit(stmt, setup, timer, number, globals)
      231            number=default_number, globals=None):
      232     """Convenience function to create Timer object and call timeit method."""
  --&gt; 233     return Timer(stmt, setup, timer, globals).timeit(number)
      234
      235 def repeat(stmt="pass", setup="pass", timer=default_timer,
  
  ~/anaconda3/lib/python3.6/timeit.py in timeit(self, number)
      176         gc.disable()
      177         try:
  --&gt; 178             timing = self.inner(it, self.timer)
      179         finally:
      180             if gcold:
  
  ~/anaconda3/lib/python3.6/timeit.py in inner(_it, _timer)
  
  ... last 4 frames repeated, from the frame below ...
  
  &lt;ipython-input-61-e079e1bd7fba&gt; in wrapper()
        7         func_name = func.__name__
        8         setup="from __main__ import {}".format(func_name)
  ----&gt; 9         op_time = timeit.timeit('{}()'.format(func_name), number = 2, setup=setup)
       10         print(ot)
       11     return wrapper
  
  RecursionError: maximum recursion depth exceeded while calling a Python object
  </code></pre>
  
  <p>I'm interested in learning what's wrong with my existing code, please don't post alternative solutions.</p>