ImportError: cannot import name Error
<p>I have a very simple test function that I need to capture its execution time using 'timeit' module, but I get an error</p>

<p>The function:</p>

<pre><code>import timeit
def test1():                            
    l = []
    for i in range(1000):
        l = l + [i]

t1 = timeit.Timer("test1()", "from __main__ import test1")
print(t1.timeit(number=1000))
</code></pre>

<blockquote>
  <p>The Error:  C:\Python34\lib\timeit.py:186: in timeit timing =
  self.inner(it, self.timer) :3: in inner ??? E<br>
  ImportError: cannot import name 'test1'
  =========== 1 error in 0.03 seconds ==============</p>
</blockquote>

<p>Can you guys help me with a solution?</p>

<p>I think there are couple of problems with your code. First for all make sure you can import timeit. And you have it as a module. For this, you can just run:</p>

<pre><code> python -m timeit '"-".join(str(n) for n in range(100))'
</code></pre>

<p>If it execute fine then you sure have the timeit module. </p>

<p>Now regarding your question. I took the liberty to rewriting it in a cleaner way.</p>

<pre><code>import timeit    

def append_list():
 num_list = []
 for i in range(1000):
         num_list.append(i)

print(timeit.timeit(stmt=append_list, number=1000)) #number is the number of repetion of the operation, in this case, 1000
# you can also run
print(timeit.timeit(stmt=append_list, number=1))   
</code></pre>

<p>Now, the above could will do what you wanted to do, i.e calculate the amount of time required to append numbers from 1 to 1000 to the list.</p>

python timeit