David Blume's GitList
Repositories
testpython.git
Code
Commits
Branches
Tags
Search
Tree:
31df010
Branches
Tags
main
python2
testpython.git
decorators
timeit.py
Add a profile decorator.
David Blume
commited
31df010
at 2021-01-09 17:52:58
timeit.py
Blame
History
Raw
import time import functools from typing import Callable def timeit(f: Callable) -> Callable: """Decorator that prints the duration of the decorated function.""" @functools.wraps(f) def wrapper(*args, **kwargs): s = time.time() r = f(*args, **kwargs) print(f'{f.__name__} took {time.time() - s:1.3f}s.') return r return wrapper