Projects/timing_decorator.py
2025-09-12 20:37:36 -07:00

18 lines
434 B
Python

import time
def timing_decorator(func):
def wrapper(*args, **kwargs):
start_time = time.time()
result = func(*args, **kwargs)
end_time = time.time()
print(f"'{func.__name__}' executed in {end_time - start_time} seconds")
return result
return wrapper
@timing_decorator
def some_function():
time.sleep(1) # Simulating a task
print("Function completed")
# Usage
some_function()