Skip to content

Instantly share code, notes, and snippets.

@TonyPythoneer
Created January 26, 2017 07:36
Show Gist options
  • Save TonyPythoneer/fb994f03c41d3c5bec242caa0f6db903 to your computer and use it in GitHub Desktop.
Save TonyPythoneer/fb994f03c41d3c5bec242caa0f6db903 to your computer and use it in GitHub Desktop.
# coding=utf-8
cond = True
def a(t):
t = t if cond else t.encode('utf-8')
return t
def b(t):
if not cond:
t = t.encode('utf-8')
return t
def a1():
u.set_password('123')
set_password = u.set_password
def a2():
set_password('123')
timeit('a1()', setup='from __main__ import a1, u', number=200000)
timeit('a2()', setup='from __main__ import a2, set_password', number=200000)
if __name__ == '__main__':
from timeit import timeit
print timeit('a(u"綫上翻譯")', setup='from __main__ import a, cond', number=100000)
print timeit('b(u"綫上翻譯")', setup='from __main__ import b, cond', number=100000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment