-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathops.bench.ts
More file actions
124 lines (117 loc) · 2.64 KB
/
Copy pathops.bench.ts
File metadata and controls
124 lines (117 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import { Bench } from "tinybench";
import { withCodSpeed } from "@codspeed/tinybench-plugin";
import { close, fixed, grow, open, pack, rgba, text } from "../ops.ts";
import type { Op } from "../ops.ts";
function makeBuf(size: number): ArrayBuffer {
return new ArrayBuffer(size);
}
let simpleOps: Op[] = [
open("root", {
layout: { width: grow(), height: grow(), direction: "ttb" },
}),
text("Hello, World!"),
close(),
];
let complexOps: Op[] = [
open("root", {
layout: { width: grow(), height: grow(), direction: "ttb" },
}),
open("header", {
layout: {
width: grow(),
height: fixed(3),
padding: { left: 1, right: 1 },
direction: "ltr",
},
bg: rgba(30, 30, 40),
border: {
color: rgba(100, 100, 120),
bottom: 1,
},
}),
text("Title", { color: rgba(255, 255, 255), fontSize: 1 }),
close(),
open("body", {
layout: {
width: grow(),
height: grow(),
direction: "ltr",
gap: 1,
},
}),
open("sidebar", {
layout: {
width: fixed(20),
height: grow(),
direction: "ttb",
padding: { left: 1, right: 1, top: 1 },
},
bg: rgba(25, 25, 35),
border: {
color: rgba(60, 60, 80),
right: 1,
},
}),
text("Menu Item 1"),
text("Menu Item 2"),
text("Menu Item 3"),
close(),
open("main", {
layout: {
width: grow(),
height: grow(),
direction: "ttb",
padding: { left: 2, top: 1 },
},
}),
text("Main content area with longer text to exercise the encoder"),
close(),
close(),
open("footer", {
layout: {
width: grow(),
height: fixed(1),
padding: { left: 1 },
direction: "ltr",
},
bg: rgba(30, 30, 40),
}),
text("Status: OK"),
close(),
close(),
];
let listOps: Op[] = [
open("root", {
layout: { width: grow(), height: grow(), direction: "ttb" },
}),
...Array.from({ length: 50 }, (_, i) => [
open(`item-${i}`, {
layout: {
width: grow(),
height: fixed(1),
padding: { left: 2 },
direction: "ltr",
},
bg: i % 2 === 0 ? rgba(30, 30, 40) : rgba(35, 35, 45),
}),
text(`List item ${i}: some description text`),
close(),
]).flat(),
close(),
];
let bench = withCodSpeed(new Bench());
bench
.add("simple tree (root + text)", () => {
let buf = makeBuf(4096);
pack(simpleOps, buf, 0);
})
.add("complex layout (header + sidebar + main + footer)", () => {
let buf = makeBuf(8192);
pack(complexOps, buf, 0);
})
.add("large list (50 items)", () => {
let buf = makeBuf(32768);
pack(listOps, buf, 0);
});
await bench.run();
console.table(bench.table());