25-cxsj-final/backend/common/timer_utils.py

18 lines
519 B
Python

import time
import functools
from typing import Tuple, Any
def time_execution(func):
"""
Decorator to measure execution time of a function.
Returns a tuple (result, execution_time_in_seconds).
"""
@functools.wraps(func)
def wrapper(*args, **kwargs) -> Tuple[Any, float]:
start_time = time.perf_counter()
result = func(*args, **kwargs)
end_time = time.perf_counter()
execution_time = end_time - start_time
return result, execution_time
return wrapper