18 lines
519 B
Python
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
|