Assignment saves time?
Hrvoje Niksic
hniksic at xemacs.org
Fri Feb 15 06:41:33 EST 2008
rpglover64 at gmail.com writes:
> I tested this using the timeit module, and though the difference was
> small, I would have expected the first code block to do slightly
> worse,
Can you post your entire benchmark, so that we can repeat it? When I
tried the obvious, I got the expected result:
$ python -m timeit -s 'l=[]' 'len(l)==1000'
1000000 loops, best of 3: 0.256 usec per loop
$ python -m timeit -s 'l=[]' 'len(l)==1000'
1000000 loops, best of 3: 0.27 usec per loop
$ python -m timeit -s 'l=[]' 's=len(l); s==1000'
1000000 loops, best of 3: 0.287 usec per loop
$ python -m timeit -s 'l=[]' 's=len(l); s==1000'
1000000 loops, best of 3: 0.299 usec per loop
More information about the Python-list
mailing list