Skip to content

Instantly share code, notes, and snippets.

@SS1031
Last active July 16, 2017 07:28
Show Gist options
  • Save SS1031/b8cabea4648e5d508987d0e330140696 to your computer and use it in GitHub Desktop.
Save SS1031/b8cabea4648e5d508987d0e330140696 to your computer and use it in GitHub Desktop.
def stopwatch(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
start = time.time()
result = func(*args, **kwargs)
end = time.time()
print("Function[{}]".format(func.__name__), ", {0:d} min {1:d} sec".format(
int(end - start) // 60, int((end - start) % 60)))
return result
return wrapper
@stopwatch
def test_watch():
summation = 0
for i in range(100000000):
summation += i
if __name__ == '__main__':
test_watch()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment