Question about timeit

Frank Millman frank at chagford.com
Fri Jul 22 02:59:11 EDT 2011


On Jul 22, 8:37 am, Stefan Behnel <stefan... at behnel.de> wrote:
> Frank Millman, 22.07.2011 08:06:
>
>
>
>
>
> > I mentioned in a recent post that I noticed an inconsistency in timeit, and
> > then reported that I must have made a mistake.
>
> > I have now identified my problem, but I don't understand it.
>
> > C:\Python32\Lib>timeit.py "int(float('165.0'))"
> > 100000 loops, best of 3: 3.52 usec per loop
>
> > C:\Python32\Lib>timeit.py "int(float('165.0'))"
> > 100000 loops, best of 3: 3.51 usec per loop
>
> > C:\Python32\Lib>timeit.py 'int(float("165.0"))'
> > 10000000 loops, best of 3: 0.0888 usec per loop
>
> > C:\Python32\Lib>timeit.py 'int(float("165.0"))'
> > 10000000 loops, best of 3: 0.0887 usec per loop
>
> > I ran them both twice just to be sure.
>
> > The first two use double-quote marks to surround the statement, and
> > single-quote marks to surround the literal inside the statement.
>
> > The second two swap the quote marks around.
>
> > Can someone explain the difference?
>
> > I am using python 3.2 on Windows Server 2003.
>
> As expected, I can't reproduce this (on Linux). Maybe your processor
> switched from power save mode to performance mode right after running the
> test a second time? Or maybe you need a better console application that
> handles quotes in a more obvious way?
>
> Note that it's common to run timeit like this: "python -m timeit".
>
> Stefan- Hide quoted text -
>
> - Show quoted text -

I tried "python -m timeit", and got exactly the same result as before.

I am using a desktop, not a laptop, so there is no power-saving mode
going on.

I am using the standard Windows 'Command Prompt' console to run this.

I tried it with python 2.6, and still get the same result.

My guess is that it is something to do with the console, but I don't
know what. If I get time over the weekend I will try to get to the
bottom of it.

Frank



More information about the Python-list mailing list