which is more pythonic/faster append or +=[]
Steven Bethard
steven.bethard at gmail.com
Thu May 10 16:39:37 EDT 2007
7stud wrote:
>> Is there any documentation for the syntax you used with timeit?
>
> This is the syntax the docs describe:
[snip
> python timeit.py [-n N] [-r N] [-s S] [-t] [-c] [-h] [statement ...]
[snip]
> Then in the examples in section 10.10.2
[snip]
> timeit.py 'try:' ' str.__nonzero__' 'except AttributeError:' ' pass'
[snip]
> and then there is Alex Martelli's syntax:
[snip]
> python -mtimeit 'L=range(3); n=23' 'x=L[:]; x.append(n)'
The following three things are equivalent:
python /path/to/<module>.py
/path/to/<module>.py # assuming the OS knows how to exec it
python -m<module> # assuming <module> is on sys.path
So that just leaves the differences between:
[-n N] [-r N] [-s S] [-t] [-c] [-h] [statement ...]
'try:' ' str.__nonzero__' 'except AttributeError:' ' pass'
'L=range(3); n=23' 'x=L[:]; x.append(n)'
Those look pretty similar to me (aside from the fact that they're
testing different things). Each argument in single quotes is a line of
the code you want timed.
HTH,
STeVe
More information about the Python-list
mailing list