Spaces:
Runtime error
Runtime error
File size: 907 Bytes
b9e2109 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | import time
import logging
from functools import wraps
logger = logging.getLogger(__name__)
def timing_decorator(func):
"""Decorator to log the execution time of a function."""
@wraps(func)
async def wrapper(*args, **kwargs):
start_time = time.time()
result = await func(*args, **kwargs)
elapsed_time = time.time() - start_time
logger.info(f"Function '{func.__name__}' completed in {elapsed_time:.2f} seconds")
return result
return wrapper
def sync_timing_decorator(func):
"""Decorator to log the execution time of a synchronous function."""
@wraps(func)
def wrapper(*args, **kwargs):
start_time = time.time()
result = func(*args, **kwargs)
elapsed_time = time.time() - start_time
logger.info(f"Function '{func.__name__}' completed in {elapsed_time:.2f} seconds")
return result
return wrapper |