70160
Ce
cel-tui / files
cel-tui / benchmarks / layout.bench.ts
2.1 KB
1/** 2 * Benchmark: layout engine — flexbox sizing and positioning. 3 * 4 * Measures the cost of computing absolute screen rects for various 5 * tree shapes and sizes. 6 */ 7 8import { bench, group, run } from "mitata"; 9import { layout } from "../packages/core/src/layout.js"; 10import { 11 appTree, 12 flatTree, 13 inkComparableTree, 14 nestedTree, 15 styledTree, 16 wrappedTextTree, 17} from "./helpers.js"; 18 19const W = 120; 20const H = 40; 21 22// --- Flat trees (varying child count) --- 23 24group("layout: flat tree", () => { 25 const t10 = flatTree(10); 26 const t100 = flatTree(100); 27 const t1000 = flatTree(1000); 28 29 bench("10 children", () => { 30 layout(t10, W, H); 31 }); 32 33 bench("100 children", () => { 34 layout(t100, W, H); 35 }); 36 37 bench("1000 children", () => { 38 layout(t1000, W, H); 39 }); 40}); 41 42// --- Nested trees (depth × breadth) --- 43 44group("layout: nested tree", () => { 45 const d3b3 = nestedTree(3, 3); // 3^3 = 27 leaves 46 const d4b3 = nestedTree(4, 3); // 3^4 = 81 leaves 47 const d3b5 = nestedTree(3, 5); // 5^3 = 125 leaves 48 49 bench("depth=3 breadth=3 (40 nodes)", () => { 50 layout(d3b3, W, H); 51 }); 52 53 bench("depth=4 breadth=3 (121 nodes)", () => { 54 layout(d4b3, W, H); 55 }); 56 57 bench("depth=3 breadth=5 (156 nodes)", () => { 58 layout(d3b5, W, H); 59 }); 60}); 61 62// --- Styled tree (inheritance overhead) --- 63 64group("layout: styled tree", () => { 65 const s50 = styledTree(50); 66 bench("50 styled groups", () => { 67 layout(s50, W, H); 68 }); 69}); 70 71// --- Word-wrap text --- 72 73group("layout: word-wrap", () => { 74 const w10 = wrappedTextTree(10); 75 const w50 = wrappedTextTree(50); 76 77 bench("10 paragraphs", () => { 78 layout(w10, W, H); 79 }); 80 81 bench("50 paragraphs", () => { 82 layout(w50, W, H); 83 }); 84}); 85 86// --- Ink-comparable tree --- 87 88group("layout: ink-comparable", () => { 89 const tree = inkComparableTree(); 90 bench("styled flex + word-wrap", () => { 91 layout(tree, 80, 24); 92 }); 93}); 94 95// --- App-like tree --- 96 97group("layout: app tree", () => { 98 const a20 = appTree(20); 99 const a100 = appTree(100); 100 101 bench("20 messages", () => { 102 layout(a20, W, H); 103 }); 104 105 bench("100 messages", () => { 106 layout(a100, W, H); 107 }); 108}); 109 110await run();