|
|
|
|
|
by tom_mellior
3059 days ago
|
|
Ah, OK. Yes, those LOAD_NAMEs are slower than LOAD_FAST. If you put the code into a function, you get this: >>> def f(foo, b):
... a = foo.bar(b)
...
>>> dis.dis(f)
2 0 LOAD_FAST 0 (foo)
3 LOAD_ATTR 0 (bar)
6 LOAD_FAST 1 (b)
9 CALL_FUNCTION 1 (1 positional, 0 keyword pair)
12 STORE_FAST 2 (a)
15 LOAD_CONST 0 (None)
18 RETURN_VALUE
LOAD_FAST is the normal case for locals inside a function. Not sure off the top of my head where LOAD_NAME would be generated in normal usage (i.e. where you don't evaluate code from a string).Edit: Also, I'm talking about Python 3. Maybe you aren't. |
|