Spaces:
Runtime error
Runtime error
| import asyncio | |
| from functools import wraps | |
| import time | |
| def time_execution(func): | |
| if asyncio.iscoroutinefunction(func): | |
| async def async_wrapper(*args, **kwargs): | |
| start_time = time.time() | |
| result = await func(*args, **kwargs) | |
| end_time = time.time() | |
| execution_time = end_time - start_time | |
| print(f"Function '{func.__name__}' executed in {execution_time:.4f} seconds") | |
| return result | |
| return async_wrapper | |
| else: | |
| def sync_wrapper(*args, **kwargs): | |
| start_time = time.time() | |
| result = func(*args, **kwargs) | |
| end_time = time.time() | |
| execution_time = end_time - start_time | |
| print(f"Function '{func.__name__}' executed in {execution_time:.4f} seconds") | |
| return result | |
| return sync_wrapper | |