Skip to content

Instantly share code, notes, and snippets.

@EdgeCaseBerg
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EdgeCaseBerg/fc93d67b9279402c7211 to your computer and use it in GitHub Desktop.
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
>>> 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