Steven Bethard a écrit : > 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:
You forgot the most important function : f3 >>> def f1((x,y)): ... print x,y ... >>> def f2(x_y): ... x,y = x_y ... print x,y ... >>> def f3(x_y): ... print x_y[0], x_y[1] ... >>> import dis >>> 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_FAST 1 (x) 15 PRINT_ITEM 16 LOAD_FAST 2 (y) 19 PRINT_ITEM 20 PRINT_NEWLINE 21 LOAD_CONST 0 (None) 24 RETURN_VALUE >>> dis.dis(f2) 2 0 LOAD_FAST 0 (x_y) 3 UNPACK_SEQUENCE 2 6 STORE_FAST 2 (x) 9 STORE_FAST 1 (y) 3 12 LOAD_FAST 2 (x) 15 PRINT_ITEM 16 LOAD_FAST 1 (y) 19 PRINT_ITEM 20 PRINT_NEWLINE 21 LOAD_CONST 0 (None) 24 RETURN_VALUE >>> dis.dis(f3) 2 0 LOAD_FAST 0 (x_y) 3 LOAD_CONST 1 (0) 6 BINARY_SUBSCR 7 PRINT_ITEM 8 LOAD_FAST 0 (x_y) 11 LOAD_CONST 2 (1) 14 BINARY_SUBSCR 15 PRINT_ITEM 16 PRINT_NEWLINE 17 LOAD_CONST 0 (None) 20 RETURN_VALUE >>> -- http://mail.python.org/mailman/listinfo/python-list