relative speed of incremention syntaxes (or "i=i+1" VS "i+=1")
Emile van Sebille
emile at fenx.com
Mon Aug 22 13:22:25 EDT 2011
On 8/22/2011 9:35 AM Emile van Sebille said...
> On 8/22/2011 2:55 AM Richard D. Moores said...
>> Coincidence?
>>
>
> Naaa.. I just ran it twice -- once per ... _this_ is coincidence. :)
>
> Microsoft Windows XP [Version 5.1.2600]
> (C) Copyright 1985-2001 Microsoft Corp.
>
> C:\Documents and Settings\Emile>python -m timeit -r 3 -s "n=0" "n=n+1"
> 10000000 loops, best of 3: 0.108 usec per loop
>
> C:\Documents and Settings\Emile>python -m timeit -r 3 -s "n=0" "n += 1"
> 10000000 loops, best of 3: 0.108 usec per loop
Actually, it's more likely I hit a minimum resolution issue -- I ran it
twenty more times and never got a different result.
Emile
More information about the Python-list
mailing list