Last active
August 29, 2015 14:20
-
-
Save EdgeCaseBerg/fc93d67b9279402c7211 to your computer and use it in GitHub Desktop.
Python shell of checking to see which one is faster, addition of strings or interpolation
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
>>> import dis | |
>>> def addStr(s): | |
... return ">" + s + "<" | |
... | |
>>> dis.dis(addStr) | |
2 0 LOAD_CONST 1 ('>') | |
3 LOAD_FAST 0 (s) | |
6 BINARY_ADD | |
7 LOAD_CONST 2 ('<') | |
10 BINARY_ADD | |
11 RETURN_VALUE | |
>>> def addStr2(s): | |
... return ">%s<" % s | |
... | |
>>> dis.dis(addStr2) | |
2 0 LOAD_CONST 1 ('>%s<') | |
3 LOAD_FAST 0 (s) | |
6 BINARY_MODULO | |
7 RETURN_VALUE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment