xonecas.io
70160
Ce

cel-tui / files

cel-tui / benchmarks / paint.bench.ts

3.0 KB
1/**
2 * Benchmark: paint — writing styled cells into the cell buffer.
3 *
4 * Measures the cost of painting laid-out trees into a CellBuffer,
5 * including text rendering, style inheritance, clipping, and scrollbars.
6 */
7
8import { CellBuffer } from "@cel-tui/core";
9import { bench, group, run } from "mitata";
10import { layout } from "../packages/core/src/layout.js";
11import { paint } from "../packages/core/src/paint.js";
12import {
13  appTree,
14  flatTree,
15  inkComparableTree,
16  nestedTree,
17  scrollableTree,
18  styledTree,
19  wrappedTextTree,
20} from "./helpers.js";
21
22const W = 120;
23const H = 40;
24
25// --- Flat tree paint ---
26
27group("paint: flat tree", () => {
28  const l10 = layout(flatTree(10), W, H);
29  const l100 = layout(flatTree(100), W, H);
30  const l1000 = layout(flatTree(1000), W, H);
31
32  bench("10 children", () => {
33    const buf = new CellBuffer(W, H);
34    paint(l10, buf);
35  });
36
37  bench("100 children", () => {
38    const buf = new CellBuffer(W, H);
39    paint(l100, buf);
40  });
41
42  bench("1000 children", () => {
43    const buf = new CellBuffer(W, H);
44    paint(l1000, buf);
45  });
46});
47
48// --- Nested tree paint ---
49
50group("paint: nested tree", () => {
51  const l = layout(nestedTree(4, 3), W, H);
52  bench("depth=4 breadth=3 (121 nodes)", () => {
53    const buf = new CellBuffer(W, H);
54    paint(l, buf);
55  });
56});
57
58// --- Styled tree (inheritance + bgColor fill) ---
59
60group("paint: styled tree", () => {
61  const l = layout(styledTree(50), W, H);
62  bench("50 styled groups", () => {
63    const buf = new CellBuffer(W, H);
64    paint(l, buf);
65  });
66});
67
68// --- Scrollable (clipping + scrollbar) ---
69
70group("paint: scrollable", () => {
71  const l = layout(scrollableTree(200), W, H);
72  bench("200 lines scrollable", () => {
73    const buf = new CellBuffer(W, H);
74    paint(l, buf);
75  });
76});
77
78// --- Word-wrap ---
79
80group("paint: word-wrap", () => {
81  const l = layout(wrappedTextTree(50), W, H);
82  bench("50 word-wrapped paragraphs", () => {
83    const buf = new CellBuffer(W, H);
84    paint(l, buf);
85  });
86});
87
88// --- Ink-comparable ---
89
90group("paint: ink-comparable", () => {
91  const l = layout(inkComparableTree(), 80, 24);
92  bench("styled flex + word-wrap", () => {
93    const buf = new CellBuffer(80, 24);
94    paint(l, buf);
95  });
96});
97
98// --- App tree ---
99
100group("paint: app tree", () => {
101  const l20 = layout(appTree(20), W, H);
102  const l100 = layout(appTree(100), W, H);
103
104  bench("20 messages", () => {
105    const buf = new CellBuffer(W, H);
106    paint(l20, buf);
107  });
108
109  bench("100 messages", () => {
110    const buf = new CellBuffer(W, H);
111    paint(l100, buf);
112  });
113});
114
115// --- Terminal sizes ---
116
117group("paint: terminal sizes", () => {
118  const tree = appTree(50);
119
120  const small = layout(tree, 80, 24);
121  const medium = layout(tree, 120, 40);
122  const large = layout(tree, 200, 50);
123
124  bench("80×24 (small)", () => {
125    const buf = new CellBuffer(80, 24);
126    paint(small, buf);
127  });
128
129  bench("120×40 (medium)", () => {
130    const buf = new CellBuffer(120, 40);
131    paint(medium, buf);
132  });
133
134  bench("200×50 (large)", () => {
135    const buf = new CellBuffer(200, 50);
136    paint(large, buf);
137  });
138});
139
140await run();