Skip to content

Commit 0af69f4

Browse files
committed
Update decorators, add timeit
1 parent c00ac6a commit 0af69f4

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

python/fedml/computing/scheduler/master/base_master_job_runner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from ....core.mlops.mlops_utils import MLOpsUtils
1717
from ..scheduler_core.log_manager import LogsManager
1818
from ..scheduler_core.metrics_manager import MetricsManager
19-
from fedml.utils.debugging import debug
19+
from fedml.utils.decorators import debug
2020
from ..scheduler_core.status_center import JobStatus
2121
from ..scheduler_core.compute_cache_manager import ComputeCacheManager
2222
from multiprocessing import Process, Queue

python/fedml/utils/debugging.py renamed to python/fedml/utils/decorators.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
from typing import Callable
22
import os
3+
import time
34
import functools
45

5-
def debug(_func: Callable=None, *, output_file="output.txt"):
66

7+
def debug(_func: Callable = None, *, output_file="output.txt"):
78
def decorator(func: Callable):
89

910
@functools.wraps(func)
@@ -36,3 +37,16 @@ def wrapper(*args, **kwargs):
3637
return decorator
3738

3839
return decorator(_func)
40+
41+
def timeit(func: Callable):
42+
"""Print the runtime of the decorated function"""
43+
functools.wraps(func)
44+
45+
def wrapper(*args, **kwargs):
46+
start = time.perf_counter()
47+
func(*args, **kwargs)
48+
end = time.perf_counter()
49+
run_time = end - start
50+
print(f"Finished {func.__name__!r} in {run_time:.4f} seconds")
51+
52+
return wrapper

0 commit comments

Comments
 (0)