Question about timeit

Frank Millman frank at chagford.com
Sat Jul 23 02:30:23 EDT 2011


On Jul 22, 2:43 pm, Thomas Jollans <t... at jollybox.de> wrote:
> On 22/07/11 14:30, Frank Millman wrote:
>
>
>
>
>
> > This is what I get after modifying timeit.py as follows -
>
> >     if args is None:
> >         args = sys.argv[1:]
> > +       print(args)
>
> > C:\>python -m timeit int(float('165.0'))
> > ["int(float('165.0'))"]
> > 100000 loops, best of 3: 3.43 usec per loop
>
> > C:\>python -m timeit int(float("165.0"))
> > ['int(float(165.0))']
> > 1000000 loops, best of 3: 1.97 usec per loop
>
> > C:\>python -m timeit "int(float('165.0'))"
> > ["int(float('165.0'))"]
> > 100000 loops, best of 3: 3.45 usec per loop
>
> > It seems that the lesson is -
>
> > 1. Use double-quotes around the command itself - may not be necessary
> > if the command does not contain spaces.
> > 2. Use single-quotes for any literals in the command.
>
> What about 'int(float("165.0"))' (single quotes around the argument)?
> Does that pass the single quotes around the argument to Python? Or does
> it eliminate all quotes?- Hide quoted text -
>
> - Show quoted text -

Here is the result -

C:\>python -m timeit 'int(float("165.0"))'
["'int(float(165.0))'"]
10000000 loops, best of 3: 0.0891 usec per loop

Frank



More information about the Python-list mailing list