Files

98 lines
2.8 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
"""基准:待办卡缩略图开关的开销(v1.0.48)
真实 App + mock 配置,同一进程里分别开关 ui.todo_thumb,测:
首铺建卡、增量刷新、拖动每帧。
用法:python tools/_bench_thumb.py [行数]
"""
import os
import sys
import time
import json
sys.path.insert(0, os.getcwd())
os.chdir(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.insert(0, os.getcwd())
import tkinter as tk
import ui.app as A
N = int(sys.argv[1]) if len(sys.argv) > 1 else 120
cfg = json.load(open('config.json', encoding='utf-8'))
cfg.setdefault('server', {})['mock'] = True
cfg.setdefault('scale', {})['simulate'] = True
cfg.setdefault('camera', {})['simulate'] = True
cfg.setdefault('ui', {})['mode'] = 'window'
cfg['ui']['todo_group'] = 'none'
A.load_config = lambda: cfg
root = tk.Tk()
root.geometry('1600x900')
app = A.App(root)
app._build()
app.ready = True
root.update()
names = ['旱黄瓜', '水果黄瓜', '红富士苹果', '马铃薯']
rows = [{'id': 'r%d' % i,
'item_name': (names[i] if i < len(names) else '商品 %d' % i),
'spec': '500g', 'unit': '斤', 'required_qty': 3.0 + i % 5,
'customer_name': '客户%d' % (i % 5), 'sku_code': 'S%d' % i}
for i in range(N)]
def clear():
for c in list(app.todo_cards.values()):
try:
c.destroy()
except Exception:
pass
app.todo_cards = {}
app.todo_rows = {}
app._shown_ids = None
for _ in range(6):
root.update()
def drag(runs=3, frames=80):
best = 9e9
for _ in range(runs):
app.todo_canvas.yview_moveto(0.0)
root.update()
t = time.perf_counter()
for i in range(frames):
app.todo_canvas.yview_moveto((i / float(frames)) * 0.5)
root.update_idletasks()
best = min(best, (time.perf_counter() - t) * 1000.0 / frames)
return best
def run(tag, thumb_on, warm=False):
app.cfg.setdefault('ui', {})['todo_thumb'] = thumb_on
clear()
t = time.perf_counter()
app._fill_todo([dict(r) for r in rows])
fill_ms = (time.perf_counter() - t) * 1000
for _ in range(40):
root.update()
time.sleep(0.01)
n = sum(1 for c in app.todo_cards.values()
if getattr(c, '_thumb_label', None) is not None)
fr = drag()
rows2 = [dict(r, required_qty=r['required_qty'] + 1) for r in rows]
t = time.perf_counter()
app._fill_todo(rows2)
upd_ms = (time.perf_counter() - t) * 1000
for _ in range(10):
root.update()
print('%s|%d 行|有图卡 %2d|首铺 %5.0f ms|增量 %4.0f ms|拖动 %5.2f ms/帧'
% (tag, N, n, fill_ms, upd_ms, fr))
run('预热 ', True)
run('A 开缩略图', True)
run('B 关缩略图', False)
run('A 再开一次', True) # 有内存缓存后应该更快
root.destroy()