Augmented assignment

Suresh Jeevanandam jm.suresh at gmail.com
Tue Feb 21 01:41:02 EST 2006


Thanks Alex. I was not aware of mtimeit.

regards,
Suresh
Alex Martelli wrote:
> Suresh Jeevanandam <jm.suresh at gmail.com> wrote:
> 
>> Hi,
>>       Is there any gain in performance because of augmented assignments.
>>
>>       x += 1  vs x = x+1
>>
>> Or are both of them the same.
> 
> Just *MEASURE*, man!
> 
> helen:~/apy alex$ python -mtimeit -s'x=0.0' 'x=x+1'
> 1000000 loops, best of 3: 0.507 usec per loop
> 
> helen:~/apy alex$ python -mtimeit -s'x=0.0' 'x+=1'
> 1000000 loops, best of 3: 0.504 usec per loop
> 
> Basically a dead draw, so use what's clearest to you.  And learn to use
> -mtimeit to satisfy most such curiosities much more effectively.
> 
> 
> Alex



More information about the Python-list mailing list