Last active
December 19, 2015 16:09
-
-
Save linkerlin/5982075 to your computer and use it in GitHub Desktop.
一个简单的Python计时器
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
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