gomoku / DI-engine /ding /utils /time_helper_base.py
zjowowen's picture
init space
079c32c
raw
history blame contribute delete
975 Bytes
class TimeWrapper(object):
"""
Overview:
Abstract class method that defines ``TimeWrapper`` class
Interfaces:
``wrapper``, ``start_time``, ``end_time``
"""
@classmethod
def wrapper(cls, fn):
"""
Overview:
Classmethod wrapper, wrap a function and automatically return its running time
Arguments:
- fn (:obj:`function`): The function to be wrap and timed
"""
def time_func(*args, **kwargs):
cls.start_time()
ret = fn(*args, **kwargs)
t = cls.end_time()
return ret, t
return time_func
@classmethod
def start_time(cls):
"""
Overview:
Abstract classmethod, start timing
"""
raise NotImplementedError
@classmethod
def end_time(cls):
"""
Overview:
Abstract classmethod, stop timing
"""
raise NotImplementedError