Skip to content

Instantly share code, notes, and snippets.

@linkerlin
Last active December 19, 2015 16:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save linkerlin/5982075 to your computer and use it in GitHub Desktop.
Save linkerlin/5982075 to your computer and use it in GitHub Desktop.
一个简单的Python计时器
class Timer(object):
def __init__(self, name):
print("%s: " % name, end="")
def __enter__(self):
self.t0 = time.time()
def __exit__(self, *args):
print("%.3fs" % (time.time() - self.t0))
with Timer("XXX"):
call_function()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment