SPB Git

Repository Public

perf-typing.mjs 4.4 KB 65 lines javascript

1/**2 * =============================================================================3 *                  SP BOUCHER | SOFTWARE & RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : Note SPBoucher AI8 * File             : tests/e2e/next/perf-typing.mjs9 * Module           : tests10 * Repository       : https://git.spboucher.ai/note-spboucher-ai11 * Project Website  : https://note.spboucher.ai12 * Created          : 2026-11-1913 * Last Modified    : 2026-11-1914 *15 * Author           : Simon-Pierre Boucher16 * Position         : Professor of Finance17 * Institution      : Université du Québec en Outaouais (UQO)18 * Organization     : SP Boucher19 * Website          : https://spboucher.ai20 * Git              : https://git.spboucher.ai21 *22 * Preferred Contact: contact@spboucher.ai23 * Development      : dev@spboucher.ai24 * Support          : support@spboucher.ai25 * Security/Admin   : admin@spboucher.ai26 *27 * Copyright (c) 202628 * Simon-Pierre Boucher29 * All rights reserved where applicable. This file is governed by the30 * applicable project license, copyright notices and relevant law.31 * Existing third-party rights and notices remain unaffected.32 *33 * License          : None specified (no license file in this repository)34 *35 * Do not embed credentials, private keys, access tokens,36 * certificates or confidential personal information.37 *38 * =============================================================================39 * END OF SP BOUCHER SOURCE HEADER40 * =============================================================================41 */4243// file: tests/e2e/next/perf-typing.mjs44// description: typing-latency probe on a 2 000-block document (keystroke → next painted frame), used before/after the Lumen upgrade.45// author: Simon-Pierre Boucher — contact@spboucher.ai46// usage: E2E_BASE_URL=http://localhost:8485 node tests/e2e/next/perf-typing.mjs [blocks=2000] [chars=80]  (needs the saved e2e session; scratch database only)47import { chromium } from "@playwright/test";48const base = process.env.E2E_BASE_URL ?? "http://localhost:8485"; const N = Number(process.argv[2] ?? 2000); const CH = Number(process.argv[3] ?? 80);49const b = await chromium.launch(); const ctx = await b.newContext({ baseURL: base, storageState: "test-results/.auth/state.json", viewport: { width: 1280, height: 800 } });50const p = await ctx.newPage();51const words = "lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua".split(" ");52const content = { type: "doc", content: Array.from({ length: N }, (_, i) => (i % 25 === 0 ? { type: "heading", attrs: { level: 2 }, content: [{ type: "text", text: `Section ${i / 25 + 1}` }] } : { type: "paragraph", content: [{ type: "text", text: Array.from({ length: 18 }, (_, k) => words[(i * 7 + k * 3) % words.length]).join(" ") }] })) };53const r = await p.request.post("/api/pages", { data: { title: `E2E-perf ${Date.now()}`, content }, headers: { origin: base, "content-type": "application/json" } }); const pg = await r.json();54const t0 = Date.now(); await p.goto(`/p/${pg.id}`); await p.locator(".ProseMirror p").first().waitFor(); const ready = Date.now() - t0;55await p.waitForTimeout(1500);56await p.locator(".ProseMirror p").nth(2).click();57await p.evaluate(() => { window.__lat = []; document.addEventListener("beforeinput", () => { const t = performance.now(); requestAnimationFrame(() => { const sync = performance.now() - t; requestAnimationFrame(() => window.__lat.push({ sync, frame: performance.now() - t })); }); }, true); });58for (let i = 0; i < CH; i++) { await p.keyboard.type("abcdefghij klmnop"[i % 17]); await p.waitForTimeout(60); }59await p.waitForTimeout(400);60const lat = await p.evaluate(() => window.__lat); const q = (a, f) => { const s = [...a].sort((x, y) => x - y); return s[Math.min(s.length - 1, Math.floor(s.length * f))]; };61const sync = lat.map((l) => l.sync), frame = lat.map((l) => l.frame);62console.log(JSON.stringify({ blocks: N, samples: lat.length, readyMs: ready, toFirstFrame: { median: +q(sync, 0.5).toFixed(1), p95: +q(sync, 0.95).toFixed(1), max: +Math.max(...sync).toFixed(1) }, toPaintedFrame: { median: +q(frame, 0.5).toFixed(1), p95: +q(frame, 0.95).toFixed(1), max: +Math.max(...frame).toFixed(1) } }));63await p.request.delete(`/api/pages/${pg.id}`, { headers: { origin: base } });64await b.close();65
Files main
Menu

Theme