File size: 975 Bytes
079c32c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
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
|