From bec3f950359e49b34ec3a0e95b7e748832ff84b6 Mon Sep 17 00:00:00 2001 From: han0 Date: Thu, 19 Nov 2020 08:16:44 +0800 Subject: [PATCH] feat: runtimer --- nc_http/tools/runtimer.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 nc_http/tools/runtimer.py 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