Created
March 2, 2021 22:42
-
-
Save gvanrossum/bd8762f4932d96db03eebc7433b28c42 to your computer and use it in GitHub Desktop.
Function and disassembly
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def f(a): | |
t = 0 | |
for x in a: | |
if x > 0: | |
t = t + x | |
return t | |
import dis | |
dis.dis(f) | |
# OUTPUT | |
2 0 LOAD_CONST 1 (0) | |
2 STORE_FAST 1 (t) | |
3 4 LOAD_FAST 0 (a) | |
6 GET_ITER | |
>> 8 FOR_ITER 20 (to 30) | |
10 STORE_FAST 2 (x) | |
4 12 LOAD_FAST 2 (x) | |
14 LOAD_CONST 1 (0) | |
16 COMPARE_OP 4 (>) | |
18 POP_JUMP_IF_FALSE 8 | |
5 20 LOAD_FAST 1 (t) | |
22 LOAD_FAST 2 (x) | |
24 BINARY_ADD | |
26 STORE_FAST 1 (t) | |
28 JUMP_ABSOLUTE 8 | |
6 >> 30 LOAD_FAST 1 (t) | |
32 RETURN_VALUE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment