forked from codefuse-ai/ModelCache
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtime.py
More file actions
19 lines (16 loc) · 551 Bytes
/
time.py
File metadata and controls
19 lines (16 loc) · 551 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# -*- coding: utf-8 -*-
import time
def time_cal(func, func_name=None, report_func=None, **kwargs):
cache = kwargs.pop("cache_obj")
def inner(*args, **kwargs):
time_start = time.time()
res = func(*args, **kwargs)
delta_time = time.time() - time_start
if cache.log_time_func:
cache.log_time_func(
func.__name__ if func_name is None else func_name, delta_time
)
if report_func is not None:
report_func(delta_time)
return res
return inner