C#3.0 and lambdas

Steven Bethard steven.bethard at gmail.com
Wed Sep 21 18:45:39 EDT 2005


Steven D'Aprano wrote:
> I would love to see your test code and profiling results that demonstrate
> that explicit tuple unpacking in the body of a function is faster than
> tuple unpacking (implicit or explicit) in the header of a function.

Should be pretty close.  I believe the byte-code is nearly identical:

py> def f1((x, y)):
...     pass
...
py> def f2(x_y):
...     x, y = x_y
...
py> dis.dis(f1)
   1           0 LOAD_FAST                0 (.0)
               3 UNPACK_SEQUENCE          2
               6 STORE_FAST               1 (x)
               9 STORE_FAST               2 (y)

   2          12 LOAD_CONST               0 (None)
              15 RETURN_VALUE
py> dis.dis(f2)
   2           0 LOAD_FAST                0 (x_y)
               3 UNPACK_SEQUENCE          2
               6 STORE_FAST               2 (x)
               9 STORE_FAST               1 (y)
              12 LOAD_CONST               0 (None)
              15 RETURN_VALUE

STeVe



More information about the Python-list mailing list