Dear All, while trying to optimize some unpack operations with self compiling code I wondered howto invoke the optimization in the exec statement. Even starting with -O or -OO yields in Python 2.5.2 the same dis.dis code, which is appended below.
My interest would be to reduce the LOAD_FAST ops of "s" with DUP_TOP on the stack (are there hash lookups behind those ?) and of course to optimize the integer arithmetics following below (removing +-0 etc). Thanks for any ideas, greetings Hermann >>> import dis >>> g=r.rra.LAST3.getter(ds=0,row=0) class fa(struct.Struct): def __init__(s): super(fa,s).__init__('d') def __call__(s,): return s.unpack_from(s.buf,5392+(((s.lastrow()-0)%2880)*3+0)*8)[0] >>> dis.dis(g.__call__) 7 0 LOAD_FAST 0 (s) 3 LOAD_ATTR 0 (unpack_from) 6 LOAD_FAST 0 (s) 9 LOAD_ATTR 1 (buf) 12 LOAD_CONST 1 (5392) 15 LOAD_FAST 0 (s) 18 LOAD_ATTR 2 (lastrow) 21 CALL_FUNCTION 0 24 LOAD_CONST 2 (0) 27 BINARY_SUBTRACT 28 LOAD_CONST 3 (2880) 31 BINARY_MODULO 32 LOAD_CONST 4 (3) 35 BINARY_MULTIPLY 36 LOAD_CONST 2 (0) 39 BINARY_ADD 40 LOAD_CONST 5 (8) 43 BINARY_MULTIPLY 44 BINARY_ADD 45 CALL_FUNCTION 2 48 LOAD_CONST 2 (0) 51 BINARY_SUBSCR 52 RETURN_VALUE -- Netzwerkadministration/Zentrale Dienste, Interdiziplinaeres Zentrum fuer wissenschaftliches Rechnen der Universitaet Heidelberg IWR; INF 368; 69120 Heidelberg; Tel: (06221)54-8236 Fax: -5224 Email: hermann.la...@iwr.uni-heidelberg.de -- http://mail.python.org/mailman/listinfo/python-list