python : timeit - Tool for measuring execution time

Ian Kelly ian.g.kelly at gmail.com
Wed Apr 22 11:33:17 EDT 2015


On Wed, Apr 22, 2015 at 7:07 AM, Michael Torrie <torriem at gmail.com> wrote:
> 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.

Actually, it's smarter than that. When running timeit from the command
line, the default is to scale the number of loops according to the
time taken. It starts at 10 and tries incremental powers of 10 until
the total time is at least 0.2 seconds.



More information about the Python-list mailing list