I'm trying to use python's dis
library to experiment with & understand performance. Below is an experiment i tried, with the results.
import disdef myfunc1(dictionary):t = tuple(dictionary.items())return tdef myfunc2(dictionary, func=tuple):t = func(dictionary.items())return t
>>> dis.dis(myfunc1)
4 0 LOAD_GLOBAL 0 (tuple)3 LOAD_FAST 0 (dictionary)6 LOAD_ATTR 1 (items)9 CALL_FUNCTION 012 CALL_FUNCTION 115 STORE_FAST 1 (t)5 18 LOAD_FAST 1 (t)21 RETURN_VALUE
>>> dis.dis(myfunc2)
4 0 LOAD_FAST 1 (func)3 LOAD_FAST 0 (dictionary)6 LOAD_ATTR 0 (items)9 CALL_FUNCTION 012 CALL_FUNCTION 115 STORE_FAST 2 (t)5 18 LOAD_FAST 2 (t)21 RETURN_VALUE
Now, i understand that...
- the
4
&5
on the far left are the line numbers - the column in the middle is the opcodes that are called by the machine
- the column on the right are the objects (with opargs?)
...But what does this all mean in terms of performance? If i were trying to make a decision on which function to use, how would i use dis
to compare the two?
Thanks in advance.