feat: runtimer

This commit is contained in:
han0
2020-11-19 08:16:44 +08:00
parent ebee06cc1b
commit bec3f95035

28
nc_http/tools/runtimer.py Normal file
View File

@@ -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