Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """a decorator for printing the time elapsed for function exectuion
- """
- import time
- from functools import wraps
- def elapsed(f):
- try:
- @wraps(f)
- def wrapper(*args, **kwds):
- start = time.time()
- result = f(*args, **kwds)
- seconds = time.time() - start
- m, s = divmod(seconds, 60)
- h, m = divmod(m, 60)
- elapsed = "{0:02.0f}h {1:02.0f}m {2:02.0f}s".format(h, m, s)
- #message = str("Time elapsed ({0}):\t{1}").format(f.__name__, elapsed)
- message = str("({0} elapsed)\n").format(elapsed)
- print(message)
- return result
- return wrapper
- except:
- pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement