加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
test_tool.py 1.14 KB
一键复制 编辑 原始数据 按行查看 历史
Arendelle 提交于 2024-08-30 17:16 . update web.py
import time
import subprocess
from typing import Callable
def timer_dec(func: Callable):
def res(*args, **kwargs):
import time
start = time.time()
result = func(*args, **kwargs)
end = time.time()
print(end - start)
return result
return res
class Timer:
def __enter__(self):
self.start = time.time()
def __exit__(self, exc_type, exc_val, traceback):
if exc_type is None:
self.end = time.time()
print("time:", self.end - self.start)
def viz_dec(func: Callable):
def res(*args, **kwargs):
import viztracer as viz
tracer = viz.VizTracer()
tracer.start()
result = func(*args, **kwargs)
tracer.stop()
tracer.save()
subprocess.call(["vizviewer", "result.json"])
return result
return res
class Viz:
def __enter__(self):
import viztracer as viz
self.tracer = viz.VizTracer()
self.tracer.start()
def __exit__(self, exc_type, exc_val, traceback):
self.tracer.stop()
self.tracer.save()
subprocess.call(["vizviewer", "result.json"])
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化