70160
Ce
cel-tui / files
cel-tui / benchmarks / e2e.bench.ts
3.0 KB
1/** 2 * Benchmark: end-to-end render pipeline. 3 * 4 * Tree construction → layout → paint → emit. 5 * This is the headline number — how fast can we go from state change 6 * to terminal output? 7 * 8 * Also includes the Ink-comparable scenario (same tree shape as Ink's 9 * benchmark/simple) for direct comparison. 10 */ 11 12import { CellBuffer, emitBuffer } from "@cel-tui/core"; 13import { bench, group, run } from "mitata"; 14import { emitDiff } from "../packages/core/src/emitter.js"; 15import { layout } from "../packages/core/src/layout.js"; 16import { paint } from "../packages/core/src/paint.js"; 17import { appTree, flatTree, inkComparableTree } from "./helpers.js"; 18 19// --- Full pipeline: tree → layout → paint → emit --- 20 21group("e2e: full pipeline", () => { 22 bench("ink-comparable (80×24)", () => { 23 const tree = inkComparableTree(); 24 const l = layout(tree, 80, 24); 25 const buf = new CellBuffer(80, 24); 26 paint(l, buf); 27 emitBuffer(buf); 28 }); 29 30 bench("app tree 20 msgs (120×40)", () => { 31 const tree = appTree(20); 32 const l = layout(tree, 120, 40); 33 const buf = new CellBuffer(120, 40); 34 paint(l, buf); 35 emitBuffer(buf); 36 }); 37 38 bench("flat 100 lines (80×24)", () => { 39 const tree = flatTree(100); 40 const l = layout(tree, 80, 24); 41 const buf = new CellBuffer(80, 24); 42 paint(l, buf); 43 emitBuffer(buf); 44 }); 45}); 46 47// --- Re-render with diff (the common case) --- 48 49group("e2e: re-render with diff", () => { 50 // Simulate: first render, then re-render identical tree (no changes) 51 const tree = inkComparableTree(); 52 const l = layout(tree, 80, 24); 53 const prevBuf = new CellBuffer(80, 24); 54 paint(l, prevBuf); 55 56 bench("ink-comparable no-change diff", () => { 57 const tree2 = inkComparableTree(); 58 const l2 = layout(tree2, 80, 24); 59 const buf = new CellBuffer(80, 24); 60 paint(l2, buf); 61 emitDiff(prevBuf, buf); 62 }); 63}); 64 65group("e2e: re-render with partial change", () => { 66 const tree1 = appTree(20); 67 const l1 = layout(tree1, 120, 40); 68 const prevBuf = new CellBuffer(120, 40); 69 paint(l1, prevBuf); 70 71 bench("app tree +1 message diff", () => { 72 const tree2 = appTree(21); 73 const l2 = layout(tree2, 120, 40); 74 const buf = new CellBuffer(120, 40); 75 paint(l2, buf); 76 emitDiff(prevBuf, buf); 77 }); 78}); 79 80// --- Ink comparison: 100k re-renders --- 81// Ink's benchmark does 100,000 rerender() calls of the same tree. 82// We measure a single re-render and also the total for 100k. 83 84group("e2e: ink comparison — re-render throughput", () => { 85 bench("single re-render (ink-comparable tree)", () => { 86 const tree = inkComparableTree(); 87 const l = layout(tree, 80, 24); 88 const buf = new CellBuffer(80, 24); 89 paint(l, buf); 90 emitBuffer(buf); 91 }); 92 93 // Measure 1000 iterations as a batch to get a total time 94 bench("1000 re-renders (ink-comparable tree)", () => { 95 for (let i = 0; i < 1000; i++) { 96 const tree = inkComparableTree(); 97 const l = layout(tree, 80, 24); 98 const buf = new CellBuffer(80, 24); 99 paint(l, buf); 100 emitBuffer(buf); 101 } 102 }); 103}); 104 105await run();