From e37e678167a23adcd2c62fd7a5b9a55a2fa50df4 Mon Sep 17 00:00:00 2001 From: SnowindMe <1945743455@qq.com> Date: Sat, 12 Apr 2025 23:41:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E4=BA=86=E4=B8=8B=E6=96=87?= =?UTF-8?q?=E6=A1=A3=E8=A7=A3=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/utils/timer_calculater.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/plugins/utils/timer_calculater.py b/src/plugins/utils/timer_calculater.py index 8fbb98728..e6491bc56 100644 --- a/src/plugins/utils/timer_calculater.py +++ b/src/plugins/utils/timer_calculater.py @@ -5,33 +5,39 @@ import asyncio """ # 更好的计时器 +支持上下文和装饰器 感谢D指导 # 用法: -- -@Timer() -def func(): - pass - -- +- 装饰器 time_dict = {} @Timer("计数", time_dict) def func(): pass +print(time_dict) -- +- 上下文_1 def func(): with Timer() as t: pass + print(t) + print(t.human_readable) -- +- 上下文_2 def func(): time_dict = {} - with Timer("计数", time_dict) as t: + with Timer("计数", time_dict): pass + print(time_dict) + +参数: +- name:计时器的名字,默认为None +- time_dict:计时器结果存储字典,默认为None +- auto_unit: 自动选择单位(为毫秒或秒/一直为秒),默认为True(为毫秒或秒) 属性:human_readable + 自定义错误:TimerTypeError """