import time from functools import wraps def measuretime(func): @wraps(func) def wrapper(*args, **kwargs): start_time = time.time() result = func(*args, **kwargs) end_time = time.time() time_it_took = end_time - start_time if isinstance(result, tuple): return (*result, time_it_took) else: return result, time_it_took return wrapper