efficiency question
diffuser78 at gmail.com
diffuser78 at gmail.com
Fri Jun 30 15:01:47 EDT 2006
can you please explain how to read these output...I mean how to
understand them.
A quick glance tells you that the latter approach has less number of
instructions and thats why its better. Any more insight would help a
lot.
MTD wrote:
> For the sake of comparison:
>
> >>> def cod(x):
> ... tupple1 = ("abc", "def", "xyz")
> ... tupple2 = ("pqr", "tuv", "123")
> ... if x in tupple1:
> ... doStuff()
> ... elif x in tupple2:
> ... doOtherStuff()
> ...
> >>> dis.dis(cod)
> 2 0 LOAD_CONST 7 (('abc', 'def', 'xyz'))
> 3 STORE_FAST 2 (tupple1)
>
> 3 6 LOAD_CONST 8 (('pqr', 'tuv', '123'))
> 9 STORE_FAST 1 (tupple2)
>
> 4 12 LOAD_FAST 0 (x)
> 15 LOAD_FAST 2 (tupple1)
> 18 COMPARE_OP 6 (in)
> 21 JUMP_IF_FALSE 11 (to 35)
> 24 POP_TOP
>
> 5 25 LOAD_GLOBAL 3 (doStuff)
> 28 CALL_FUNCTION 0
> 31 POP_TOP
> 32 JUMP_FORWARD 25 (to 60)
> >> 35 POP_TOP
>
> 6 36 LOAD_FAST 0 (x)
> 39 LOAD_FAST 1 (tupple2)
> 42 COMPARE_OP 6 (in)
> 45 JUMP_IF_FALSE 11 (to 59)
> 48 POP_TOP
>
> 7 49 LOAD_GLOBAL 4 (doOtherStuff)
> 52 CALL_FUNCTION 0
> 55 POP_TOP
> 56 JUMP_FORWARD 1 (to 60)
> >> 59 POP_TOP
> >> 60 LOAD_CONST 0 (None)
> 63 RETURN_VALUE
More information about the Python-list
mailing list