From bfbc1120ecb95c444ac4ca0fbb98a3e77cf038ba Mon Sep 17 00:00:00 2001 From: zj3D Date: Sat, 16 Mar 2024 14:06:31 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=90=E8=A1=8C=E6=97=B6=E9=97=B4=E8=A3=85?= =?UTF-8?q?=E9=A5=B0=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cppy/cp_util.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/cppy/cp_util.py b/cppy/cp_util.py index 56fe658..206ab37 100644 --- a/cppy/cp_util.py +++ b/cppy/cp_util.py @@ -1,6 +1,6 @@ import site -import os,re +import os,re,time import string,operator ################################################################################ @@ -21,7 +21,7 @@ testfilepath = os.path.join(basePath, 'cppy','data',testfilename ) ################################################################################ -# 函数 +# 项目函数 ################################################################################ def read_file(path_to_file): with open(path_to_file,encoding='utf-8') as f: @@ -68,5 +68,19 @@ def print_word_freqs( word_freqs, n = 10): print( w, '-', c ) +################################################################################ +# 通用工具 +################################################################################ + +def timing_decorator(func): + def wrapper(*args, **kwargs): + start_time = time.time() # 记录开始时间 + result = func(*args, **kwargs) # 调用原始函数 + end_time = time.time() # 记录结束时间 + run_time = end_time - start_time # 计算运行时间 + print(f"{func.__name__} 运行时间: {run_time*1000:.2f} 秒") + return result + return wrapper + def test(): print( 'cppy welcome' ) \ No newline at end of file