diff --git a/nc_http/tools/runtimer.py b/nc_http/tools/runtimer.py new file mode 100644 index 0000000..194a230 --- /dev/null +++ b/nc_http/tools/runtimer.py @@ -0,0 +1,28 @@ +class RunTimer: + """ + 运行计时器 + :example: + >>> RunTimer.set_point() + >>> for i in range(1000): + >>> print(i) + >>> RunTimer.set_point() + >>> RunTimer.check() + """ + time = None + profile = [] + + @classmethod + def set_point(cls): + import time + time = time.time() + if cls.time: + cls.profile.append(time - cls.time) + cls.time = time + + @classmethod + def check(cls): + print(cls.profile) + cls.time = None + profile = cls.profile.copy() + cls.profile = [] + return profile