Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #10086

Re: Question about timeit

From Stefan Behnel <stefan_ml@behnel.de>
Subject Re: Question about timeit
Date 2011-07-22 10:34 +0200
References <j0b41p$krj$1@dough.gmane.org> <mailman.1350.1311316646.1164.python-list@python.org> <83238f45-e72d-4ea9-9b4a-a42d26cd7282@x7g2000vbk.googlegroups.com> <j0bb5t$11c$1@r03.glglgl.eu>
Newsgroups comp.lang.python
Message-ID <mailman.1353.1311323659.1164.python-list@python.org> (permalink)

Show all headers | View raw


Thomas Rachel, 22.07.2011 10:08:
> Am 22.07.2011 08:59 schrieb Frank Millman:
>
>> 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.
>
> I would guess that in the first case, python (resp. timeit.py) gets the
> intended code for execution: int(float('165.0')). I. e., give the string to
> float() and its result to int().
>
> In the second case, however, timeit.py gets the string
> 'int(float("165.0"))' and evaluates it - which is a matter of
> sub-microseconds.
>
> The reason for this is that the Windows "shell" removes the "" in the first
> case, but not the '' in the second case.

Good call. Or maybe it actually gets the code 'int(float(165.0))' in the 
second case, so it doesn't need to parse the string into a float. But given 
the huge difference in the timings, I would second your guess that it just 
evaluates the plain string itself instead of the code.

Stefan

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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