ding.utils.time_helper_base¶
ding.utils.time_helper_base
¶
TimeWrapper
¶
Bases: object
Overview
Abstract class method that defines TimeWrapper class
Interfaces
wrapper, start_time, end_time
wrapper(fn)
classmethod
¶
Overview
Classmethod wrapper, wrap a function and automatically return its running time
Arguments:
- fn (:obj:function): The function to be wrap and timed
start_time()
classmethod
¶
Overview
Abstract classmethod, start timing
end_time()
classmethod
¶
Overview
Abstract classmethod, stop timing
Full Source Code
../ding/utils/time_helper_base.py
1class TimeWrapper(object): 2 """ 3 Overview: 4 Abstract class method that defines ``TimeWrapper`` class 5 6 Interfaces: 7 ``wrapper``, ``start_time``, ``end_time`` 8 """ 9 10 @classmethod 11 def wrapper(cls, fn): 12 """ 13 Overview: 14 Classmethod wrapper, wrap a function and automatically return its running time 15 Arguments: 16 - fn (:obj:`function`): The function to be wrap and timed 17 """ 18 19 def time_func(*args, **kwargs): 20 cls.start_time() 21 ret = fn(*args, **kwargs) 22 t = cls.end_time() 23 return ret, t 24 25 return time_func 26 27 @classmethod 28 def start_time(cls): 29 """ 30 Overview: 31 Abstract classmethod, start timing 32 """ 33 raise NotImplementedError 34 35 @classmethod 36 def end_time(cls): 37 """ 38 Overview: 39 Abstract classmethod, stop timing 40 """ 41 raise NotImplementedError