Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #10077
| From | Stefan Behnel <stefan_ml@behnel.de> |
|---|---|
| Subject | Re: Question about timeit |
| Date | 2011-07-22 08:37 +0200 |
| References | <j0b41p$krj$1@dough.gmane.org> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1350.1311316646.1164.python-list@python.org> (permalink) |
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
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Re: Question about timeit Stefan Behnel <stefan_ml@behnel.de> - 2011-07-22 08:37 +0200
Re: Question about timeit Frank Millman <frank@chagford.com> - 2011-07-21 23:59 -0700
Re: Question about timeit Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2011-07-22 10:08 +0200
Re: Question about timeit Stefan Behnel <stefan_ml@behnel.de> - 2011-07-22 10:34 +0200
Re: Question about timeit Frank Millman <frank@chagford.com> - 2011-07-22 05:30 -0700
Re: Question about timeit Thomas Jollans <t@jollybox.de> - 2011-07-22 14:43 +0200
Re: Question about timeit Frank Millman <frank@chagford.com> - 2011-07-22 23:30 -0700
csiph-web