Augmented assignment
Alex Martelli
aleaxit at yahoo.com
Tue Feb 21 00:47:54 EST 2006
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