It feels so good, so quick and not C!
Delaney, Timothy C (Timothy)
tdelaney at avaya.com
Tue Mar 18 23:21:58 EST 2003
> From: Steven Taschuk [mailto:staschuk at telusplanet.net]
>
> > (3) The cuteness of swapping by "x, y = y, x" hides the overhead of
> > packing and unpacking a 2-tuple, which may or may not be faster than
> > the traditional 3-assignment method.
>
> I confess a weakness for the cute swapping method; on my machine
> it is, in fact, perhaps 5% slower. I don't usually worry about it.
Indeed. Readability comes first. Not polluting the namespace is also important. Performance (esp. such a small improvement) is well and truly down the list - until proven that you need it.
In any case, IIRC psyco will use virtual-time tuples in the swap case, leading to effectively no performance loss :)
Tim Delaney
More information about the Python-list
mailing list