Phillip J. Eby wrote: > Were these timings done with the code that turns (1,2,3) into a constant?
I used a stock 2.4 from python.org, which seems to do this (for tuples, not for lists). > Also, I presume that these timings still include extra LOAD_FAST operations > that could be replaced > with DUP_TOP in the actual expansion, although I don't know how much > difference that would make in > practice, since saving the argument fetch might be offset by the need to swap > and pop at the end. here's the disassembly: >>> dis.dis(compile("if a in (1, 2, 3): pass", "", "exec")) 1 0 LOAD_NAME 0 (a) 3 LOAD_CONST 4 ((1, 2, 3)) 6 COMPARE_OP 6 (in) 9 JUMP_IF_FALSE 4 (to 16) 12 POP_TOP 13 JUMP_FORWARD 1 (to 17) >> 16 POP_TOP >> 17 LOAD_CONST 3 (None) 20 RETURN_VALUE >>> dis.dis(compile("if a == 1 or a == 2 or a == 3: pass", "", "exec")) 1 0 LOAD_NAME 0 (a) 3 LOAD_CONST 0 (1) 6 COMPARE_OP 2 (==) 9 JUMP_IF_TRUE 26 (to 38) 12 POP_TOP 13 LOAD_NAME 0 (a) 16 LOAD_CONST 1 (2) 19 COMPARE_OP 2 (==) 22 JUMP_IF_TRUE 13 (to 38) 25 POP_TOP 26 LOAD_NAME 0 (a) 29 LOAD_CONST 2 (3) 32 COMPARE_OP 2 (==) 35 JUMP_IF_FALSE 4 (to 42) >> 38 POP_TOP 39 JUMP_FORWARD 1 (to 43) >> 42 POP_TOP >> 43 LOAD_CONST 3 (None) 46 RETURN_VALUE </F> _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com