xonecas.io
70160
Ce

cel-tui / files

cel-tui / benchmarks / width.bench.ts

1.1 KB
1/**
2 * Benchmark: visibleWidth — character width measurement.
3 *
4 * This is the hottest path in the framework. Every text node, every
5 * word-wrap calculation, every cursor position calls visibleWidth().
6 */
7
8import { visibleWidth } from "@cel-tui/core";
9import { bench, group, run } from "mitata";
10import { ASCII_STRING, CJK_EMOJI_STRING, MIXED_STRING } from "./helpers.js";
11
12// --- Benchmarks ---
13
14group("visibleWidth", () => {
15  bench("ASCII (64 chars)", () => {
16    visibleWidth(ASCII_STRING);
17  });
18
19  bench("ASCII short (5 chars)", () => {
20    visibleWidth("hello");
21  });
22
23  bench("CJK + emoji (26 graphemes)", () => {
24    visibleWidth(CJK_EMOJI_STRING);
25  });
26
27  bench("mixed ASCII + CJK (60 chars)", () => {
28    visibleWidth(MIXED_STRING);
29  });
30
31  const longAscii = ASCII_STRING.repeat(10);
32  bench("ASCII long (640 chars)", () => {
33    visibleWidth(longAscii);
34  });
35
36  const ansiString = "\x1b[31mRed\x1b[0m \x1b[1;32mBold Green\x1b[0m normal";
37  bench("ANSI escape sequences", () => {
38    visibleWidth(ansiString);
39  });
40
41  bench("empty string", () => {
42    visibleWidth("");
43  });
44});
45
46await run();