Assignment saves time?

rpglover64 at gmail.com rpglover64 at gmail.com
Sat Feb 16 15:57:54 EST 2008


I ran the following in the python shell:

>>> import timeit
>>> storeit=timeit.Timer('s=len(li);s==1000', 'li=range(1000)')
>>> checkit=timeit.Timer('len(li)==1000', 'li=range(1000)')
>>> listofresults=[(min(storeit.repeat(5)),min(checkit.repeat(5))) for i in xrange(20)]

listofresults contained these values

(0.25506401062011719, 0.25763511657714844)
(0.2541499137878418, 0.25717496871948242)
(0.25352811813354492, 0.25570392608642578)
(0.25349903106689453, 0.25812816619873047)
(0.25426197052001953, 0.25819206237792969)
(0.25236606597900391, 0.25693607330322266)
(0.25433588027954102, 0.25758695602416992)
(0.25356602668762207, 0.25770902633666992)
(0.25328993797302246, 0.25844502449035645)
(0.25414395332336426, 0.25747895240783691)
(0.25800919532775879, 0.25954699516296387)
(0.25691604614257812, 0.25997209548950195)
(0.25767397880554199, 0.25859308242797852)
(0.25512409210205078, 0.26129603385925293)
(0.25843596458435059, 0.25791501998901367)
(0.2594301700592041, 0.2605140209197998)
(0.25701212882995605, 0.25839614868164062)
(0.25591516494750977, 0.26186609268188477)
(0.25582718849182129, 0.25893092155456543)
(0.2576749324798584, 0.25799012184143066)

in only one of these pairs is the first value larger than the second
value.  I don't think this constitutes consistently, but I do think it
counts as frequently.



More information about the Python-list mailing list