title: Struggling with Python timeit
body: <p>I'm struggling with the timeit function in Python, and, on a deeper level, I find myself very frustrated by the quirks of this function. I'm hoping I can get some help with both issues here.</p>
  
  <p>I have a script (call it <code>my_script.py</code>) with a lot of different function definitions, and then a lot of other stuff being calculated below them all. I want to time only one of these functions in particular - let's call it <code>level_99_function(x)</code>. I have a big array stored in <code>my_input</code>. My first attempt:</p>
  
  <pre><code>timeit.timeit('f1(x)', setup = 'my_input')
  </code></pre>
  
  <p>Python returns the error: <code>NameError: global name 'angle' is not defined</code>.</p>
  
  <p>Now my second attempt is to do the following:</p>
  
  <pre><code>print timeit.timeit('level_99_function(x)', setup = 'import numpy as np; import my_script.py; x= np.linspace(0,100)')
  </code></pre>
  
  <p>This doesn't generate any errors, but the problem is two-fold. First, and most importantly, it still doesn't time the <code>level_99_function</code> (or maybe it just doesn't print to output of the timer for whatever reason?) Second, the <code>import</code> statement seems to be running the entire script on import, which takes forever because of all the stuff I've got in this script aside from my <code>level_99_function</code>. </p>
  
  <p>How do I get the timing of the function in question here? And on a more philosophical level, why is this such a struggle in Python? I've already got a variable and a function defined; all I want to do is time that function call with that variable. It would be nice to not have to write a super long line of code, or write multiple lines of code, or have to import things or any of that stuff. It's as easy as <code>tic</code> and <code>toc</code> in Matlab. I guess the corresponding Python commands would be to use 'time.clock()' before and after the function call, but I've read that this can be inaccurate and misleading.</p>