python : timeit - Tool for measuring execution time

Michael Torrie torriem at
Wed Apr 22 15:07:36 CEST 2015

On 04/21/2015 09:31 PM, Ganesh Pal wrote:
> Iam not able to understand what  why only 10 loops were run ? what
> does this mean and how  does this work ?

I have a hunch you're mistakenly thinking that Python is only running
through ten iterations of your for i in range(1000000) loop.  This is
not the case.  The entire thing is running (all 1000000 iterations of
your loop), but is run ten times, as that is the default for timeit
unless you specify that you want to run it more times.  Hope this helps.

Basically timeit is doing something like this:

def mycode():
    for i in range(1000000):

for x in range(10):

And then collecting timing statistics on the ten passes.

More information about the Python-list mailing list