Created
May 9, 2013 15:11
-
-
Save durden/5548064 to your computer and use it in GitHub Desktop.
Snippet to disassemble single line code string
This file contains 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
# Taken from: http://stackoverflow.com/questions/13270888/why-is-startswith-slower-than-slicing | |
import dis | |
dis_it = lambda x: dis.dis(compile(x, '<none>', 'eval')) | |
#x = range(1000) | |
#>>> dis_it('x[::-1]') | |
#1 0 LOAD_NAME 0 (x) | |
#3 LOAD_CONST 0 (None) | |
#6 LOAD_CONST 0 (None) | |
#9 LOAD_CONST 1 (-1) | |
#12 BUILD_SLICE 3 | |
#15 BINARY_SUBSCR | |
#16 RETURN_VALUE | |
#>>> dis_it('reversed(x)') | |
#1 0 LOAD_NAME 0 (reversed) | |
#3 LOAD_NAME 1 (x) | |
#6 CALL_FUNCTION 1 | |
#9 RETURN_VALUE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment