Files
deepgrain-foundry/tools/perf.py
T
44r0n7andClaude Opus 5.5 ce7df82b01 Run browser tests locally: Playwright 1.64.1 in .venv, scripts switch to it on their own
The browser tests and screenshot tools now work with plain python3 on a machine whose
system Python refuses pip installs: tools/use_venv.py re-runs them with the repo's .venv.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-23 16:50:15 -04:00

34 lines
1.6 KiB
Python

"""Times the renderer and the simulation in a headless browser: light, drawWorld (with and without
light and glow), the pixel upload and blit, and one simulation tick, in ms. Rebuild first.
python3 tools/perf.py
"""
import sys, pathlib
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent))
from use_venv import ensure_playwright; ensure_playwright()
from playwright.sync_api import sync_playwright
root = pathlib.Path(__file__).resolve().parent.parent
url = (root / 'dist' / 'index.html').as_uri()
with sync_playwright() as p:
b = p.chromium.launch(args=['--enable-gpu-rasterization','--ignore-gpu-blocklist'])
pg = b.new_page(viewport={'width': 1440, 'height': 860})
pg.goto(url); pg.wait_for_timeout(300)
pg.evaluate("startNewWorld(424242, 1024, 640)")
pg.wait_for_function('GAME.running === true', timeout=20000)
pg.wait_for_timeout(500)
res = pg.evaluate('''() => {
const t = (f, n) => { const a = performance.now(); for (let k=0;k<n;k++) f(); return ((performance.now()-a)/n).toFixed(2); };
const out = {};
out.light = t(() => computeLight(), 20);
out.drawWorld = t(() => drawWorld(), 20);
SET.lighting = 'off'; out.drawWorldNoLight = t(() => drawWorld(), 20); SET.lighting='full';
SET.glow = 'off'; out.drawWorldNoGlow = t(() => drawWorld(), 20); SET.glow='low';
out.put = t(() => { R.bctx.putImageData(R.img,0,0); }, 20);
out.blit = t(() => { R.ctx.drawImage(R.buf, 0, 0, R.bw, R.bh, 0, 0, R.bw*R.zp, R.bh*R.zp); }, 20);
out.sim = t(() => simTick(), 60);
out.view = [R.bw, R.bh, R.zp, R.lw, R.lh];
return out;
}''')
print(res)
b.close()