Optimisation problem

Greg Ewing see_reply_address at something.invalid
Tue Nov 12 20:03:04 EST 2002


'm suregabor wrote:

> you're saying that for example
> 
> x,y = 2,4 
> 
> creates a tuple?
> 
> i thought thatr x,y=2,4 is the same as x=2;y=4


The result is the same, but the experiment below demonstrates
that the former is implemented by building a tuple and then
immediately unpacking it again.

This surprised me, because I thought someone claimed a while
ago that this case was optimised. But apparently it's not!

(I tried it with python -O too, and the result was the same.)



Python 2.2 (#1, Jul 11 2002, 14:19:37)
[GCC 3.0.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> import dis
 >>> def f():
...  x,y = 2,4
...
 >>> dis.dis(f)
           0 SET_LINENO               1

           3 SET_LINENO               2
           6 LOAD_CONST               1 (2)
           9 LOAD_CONST               2 (4)
          12 BUILD_TUPLE              2
          15 UNPACK_SEQUENCE          2
          18 STORE_FAST               1 (x)
          21 STORE_FAST               0 (y)
          24 LOAD_CONST               0 (None)
          27 RETURN_VALUE
 >>>



-- 
Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg




More information about the Python-list mailing list