@wxn0brp/db-benchmark 0.0.0-stage → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +9 -2
- package/package.json +34 -5
- package/src/custom/dir-index.ts +7 -0
- package/src/custom/sqlite.ts +41 -0
- package/src/db.ts +13 -0
- package/src/generate-static.ts +35 -0
- package/src/generate.ts +50 -0
- package/src/index.ts +31 -0
- package/src/large.ts +107 -0
- package/src/local/args.ts +63 -0
- package/src/local/cloud.ts +143 -0
- package/src/local/compare.ts +159 -0
- package/src/local/display.ts +84 -0
- package/src/local/index.ts +113 -0
- package/src/page/cache.ts +33 -0
- package/src/page/compare.ts +435 -0
- package/src/page/index.ts +113 -0
- package/src/page/local.ts +188 -0
- package/src/page/summary.ts +164 -0
- package/src/page/tables.ts +212 -0
- package/src/page/types.ts +33 -0
- package/src/page/utils.ts +58 -0
- package/src/page/var.ts +31 -0
- package/src/run.ts +25 -0
- package/src/small.ts +95 -0
- package/src/utils.ts +71 -0
|
@@ -0,0 +1,435 @@
|
|
|
1
|
+
import { adapterName, fmt } from "./utils";
|
|
2
|
+
import { Entry } from "./types";
|
|
3
|
+
import { state } from "./var";
|
|
4
|
+
|
|
5
|
+
function getPlatformsForAdapter(adapter: string): string[] {
|
|
6
|
+
return [
|
|
7
|
+
...new Set(
|
|
8
|
+
state.entries
|
|
9
|
+
.filter(e => e.info.adapter === adapter)
|
|
10
|
+
.map(e => `${e.info.ver}__${e.info.os}`),
|
|
11
|
+
),
|
|
12
|
+
].sort((a, b) => {
|
|
13
|
+
const [verA, osA] = a.split("__");
|
|
14
|
+
const [verB, osB] = b.split("__");
|
|
15
|
+
if (verA === "bun" && verB !== "bun") return -1;
|
|
16
|
+
if (verB === "bun" && verA !== "bun") return 1;
|
|
17
|
+
if (verA !== verB) return verB.localeCompare(verA);
|
|
18
|
+
return osA.localeCompare(osB);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function formatPlatform(platform: string): string {
|
|
23
|
+
const [ver, os] = platform.split("__");
|
|
24
|
+
return ver === "bun" ? `bun / ${os}` : `node ${ver} / ${os}`;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
let selectedBasePlatforms: Set<string> = new Set();
|
|
28
|
+
let selectedTargetPlatforms: Set<string> = new Set();
|
|
29
|
+
let currentSort: "name" | "diff" | "winner" = "name";
|
|
30
|
+
let currentFilter: "all" | "faster" | "slower" | "equal" = "all";
|
|
31
|
+
|
|
32
|
+
export function renderCompare() {
|
|
33
|
+
const adapters = [
|
|
34
|
+
...new Set(state.entries.map(e => e.info.adapter)),
|
|
35
|
+
].sort();
|
|
36
|
+
const baseSel = document.querySelector<HTMLSelectElement>("#compare-base");
|
|
37
|
+
const targetSel =
|
|
38
|
+
document.querySelector<HTMLSelectElement>("#compare-target");
|
|
39
|
+
|
|
40
|
+
const opts = adapters
|
|
41
|
+
.map(a => `<option value="${a}">${adapterName(a)}</option>`)
|
|
42
|
+
.join("");
|
|
43
|
+
baseSel.innerHTML = opts;
|
|
44
|
+
targetSel.innerHTML = opts;
|
|
45
|
+
|
|
46
|
+
if (adapters.length > 1) targetSel.selectedIndex = 1;
|
|
47
|
+
|
|
48
|
+
function updatePlatformChips() {
|
|
49
|
+
const basePlatforms = getPlatformsForAdapter(baseSel.value);
|
|
50
|
+
const targetPlatforms = getPlatformsForAdapter(targetSel.value);
|
|
51
|
+
|
|
52
|
+
selectedBasePlatforms = new Set(basePlatforms);
|
|
53
|
+
selectedTargetPlatforms = new Set(targetPlatforms);
|
|
54
|
+
|
|
55
|
+
renderPlatformChips(
|
|
56
|
+
"compare-base-chips",
|
|
57
|
+
basePlatforms,
|
|
58
|
+
selectedBasePlatforms,
|
|
59
|
+
(platform, checked) => {
|
|
60
|
+
if (checked) selectedBasePlatforms.add(platform);
|
|
61
|
+
else selectedBasePlatforms.delete(platform);
|
|
62
|
+
updateCompareResults();
|
|
63
|
+
},
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
renderPlatformChips(
|
|
67
|
+
"compare-target-chips",
|
|
68
|
+
targetPlatforms,
|
|
69
|
+
selectedTargetPlatforms,
|
|
70
|
+
(platform, checked) => {
|
|
71
|
+
if (checked) selectedTargetPlatforms.add(platform);
|
|
72
|
+
else selectedTargetPlatforms.delete(platform);
|
|
73
|
+
updateCompareResults();
|
|
74
|
+
},
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function updateCompareResults() {
|
|
79
|
+
doCompare(
|
|
80
|
+
baseSel.value,
|
|
81
|
+
targetSel.value,
|
|
82
|
+
Array.from(selectedBasePlatforms),
|
|
83
|
+
Array.from(selectedTargetPlatforms),
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
baseSel.addEventListener("change", () => {
|
|
88
|
+
updatePlatformChips();
|
|
89
|
+
updateCompareResults();
|
|
90
|
+
});
|
|
91
|
+
targetSel.addEventListener("change", () => {
|
|
92
|
+
updatePlatformChips();
|
|
93
|
+
updateCompareResults();
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
document.querySelectorAll("[data-sort]").forEach(btn => {
|
|
97
|
+
btn.addEventListener("click", () => {
|
|
98
|
+
document
|
|
99
|
+
.querySelectorAll("[data-sort]")
|
|
100
|
+
.forEach(b => b.classList.remove("active"));
|
|
101
|
+
btn.classList.add("active");
|
|
102
|
+
currentSort = (btn as HTMLElement).dataset.sort as any;
|
|
103
|
+
updateCompareResults();
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
document.querySelectorAll("[data-filter]").forEach(btn => {
|
|
108
|
+
btn.addEventListener("click", () => {
|
|
109
|
+
document
|
|
110
|
+
.querySelectorAll("[data-filter]")
|
|
111
|
+
.forEach(b => b.classList.remove("active"));
|
|
112
|
+
btn.classList.add("active");
|
|
113
|
+
currentFilter = (btn as HTMLElement).dataset.filter as any;
|
|
114
|
+
updateCompareResults();
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
updatePlatformChips();
|
|
119
|
+
updateCompareResults();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function renderPlatformChips(
|
|
123
|
+
containerId: string,
|
|
124
|
+
platforms: string[],
|
|
125
|
+
selected: Set<string>,
|
|
126
|
+
onChange: (platform: string, checked: boolean) => void,
|
|
127
|
+
) {
|
|
128
|
+
const container = document.querySelector<HTMLDivElement>(`#${containerId}`);
|
|
129
|
+
if (!container) return;
|
|
130
|
+
|
|
131
|
+
container.innerHTML = platforms
|
|
132
|
+
.map(p => {
|
|
133
|
+
const checked = selected.has(p) ? "checked" : "";
|
|
134
|
+
return `<label class="platform-chip ${checked ? "active" : ""}">
|
|
135
|
+
<input type="checkbox" value="${p}" ${checked} style="display:none;">
|
|
136
|
+
${formatPlatform(p)}
|
|
137
|
+
</label>`;
|
|
138
|
+
})
|
|
139
|
+
.join("");
|
|
140
|
+
|
|
141
|
+
container.querySelectorAll("label.platform-chip").forEach(label => {
|
|
142
|
+
label.addEventListener("click", e => {
|
|
143
|
+
e.preventDefault();
|
|
144
|
+
const input = label.querySelector("input");
|
|
145
|
+
const isChecked = input.checked;
|
|
146
|
+
input.checked = !isChecked;
|
|
147
|
+
label.classList.toggle("active");
|
|
148
|
+
onChange(input.value, !isChecked);
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function filterEntriesByPlatforms(
|
|
154
|
+
entries: Entry[],
|
|
155
|
+
adapter: string,
|
|
156
|
+
platforms: string[],
|
|
157
|
+
): Entry[] {
|
|
158
|
+
return entries.filter(e => {
|
|
159
|
+
if (e.info.adapter !== adapter) return false;
|
|
160
|
+
const key = `${e.info.ver}__${e.info.os}`;
|
|
161
|
+
return platforms.includes(key);
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function stddev(values: number[]): number {
|
|
166
|
+
if (values.length < 2) return 0;
|
|
167
|
+
const avg = values.reduce((a, b) => a + b, 0) / values.length;
|
|
168
|
+
const sq = values.map(v => (v - avg) ** 2);
|
|
169
|
+
return Math.sqrt(sq.reduce((a, b) => a + b, 0) / (values.length - 1));
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
interface CompareRow {
|
|
173
|
+
op: string;
|
|
174
|
+
bAvg: number;
|
|
175
|
+
tAvg: number;
|
|
176
|
+
ratio: number;
|
|
177
|
+
statClass: string;
|
|
178
|
+
text: string;
|
|
179
|
+
titleText: string;
|
|
180
|
+
baseMin: number;
|
|
181
|
+
baseMax: number;
|
|
182
|
+
baseStd: number;
|
|
183
|
+
baseCount: number;
|
|
184
|
+
targetMin: number;
|
|
185
|
+
targetMax: number;
|
|
186
|
+
targetStd: number;
|
|
187
|
+
targetCount: number;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function buildCompareRows(
|
|
191
|
+
baseA: string,
|
|
192
|
+
targetA: string,
|
|
193
|
+
basePlatforms: string[],
|
|
194
|
+
targetPlatforms: string[],
|
|
195
|
+
): CompareRow[] {
|
|
196
|
+
const { entries } = state;
|
|
197
|
+
const allOps = [
|
|
198
|
+
...new Set(entries.flatMap(e => e.data.results.map(r => r.name))),
|
|
199
|
+
].sort();
|
|
200
|
+
|
|
201
|
+
const baseEntries = filterEntriesByPlatforms(entries, baseA, basePlatforms);
|
|
202
|
+
const targetEntries = filterEntriesByPlatforms(
|
|
203
|
+
entries,
|
|
204
|
+
targetA,
|
|
205
|
+
targetPlatforms,
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
const rows: CompareRow[] = [];
|
|
209
|
+
|
|
210
|
+
for (const op of allOps) {
|
|
211
|
+
const baseTimes = baseEntries
|
|
212
|
+
.map(e => e.data.results.find(r => r.name === op)?.time)
|
|
213
|
+
.filter((t): t is number => t !== undefined);
|
|
214
|
+
const targetTimes = targetEntries
|
|
215
|
+
.map(e => e.data.results.find(r => r.name === op)?.time)
|
|
216
|
+
.filter((t): t is number => t !== undefined);
|
|
217
|
+
|
|
218
|
+
if (!baseTimes.length || !targetTimes.length) continue;
|
|
219
|
+
|
|
220
|
+
const bAvg = baseTimes.reduce((a, b) => a + b, 0) / baseTimes.length;
|
|
221
|
+
const tAvg = targetTimes.reduce((a, b) => a + b, 0) / targetTimes.length;
|
|
222
|
+
|
|
223
|
+
const ratio = bAvg / tAvg;
|
|
224
|
+
let statClass = "stat-equal";
|
|
225
|
+
let text = "Equal";
|
|
226
|
+
|
|
227
|
+
const isTiny = Math.min(bAvg, tAvg) < 1;
|
|
228
|
+
const fastRatio = isTiny ? 1.25 : 1.05;
|
|
229
|
+
const slowRatio = isTiny ? 0.75 : 0.95;
|
|
230
|
+
|
|
231
|
+
if (ratio < slowRatio) {
|
|
232
|
+
statClass = "stat-faster";
|
|
233
|
+
text = `${adapterName(baseA)} ${(1 / ratio).toFixed(2)}x faster`;
|
|
234
|
+
} else if (ratio > fastRatio) {
|
|
235
|
+
statClass = "stat-slower";
|
|
236
|
+
text = `${adapterName(targetA)} ${ratio.toFixed(2)}x faster`;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
let titleText = "Adapters are equal performance-wise";
|
|
240
|
+
if (statClass !== "stat-equal") {
|
|
241
|
+
const betterAdapter = bAvg < tAvg ? baseA : targetA;
|
|
242
|
+
titleText = `${adapterName(betterAdapter)} is faster`;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
rows.push({
|
|
246
|
+
op,
|
|
247
|
+
bAvg,
|
|
248
|
+
tAvg,
|
|
249
|
+
ratio,
|
|
250
|
+
statClass,
|
|
251
|
+
text,
|
|
252
|
+
titleText,
|
|
253
|
+
baseMin: Math.min(...baseTimes),
|
|
254
|
+
baseMax: Math.max(...baseTimes),
|
|
255
|
+
baseStd: stddev(baseTimes),
|
|
256
|
+
baseCount: baseTimes.length,
|
|
257
|
+
targetMin: Math.min(...targetTimes),
|
|
258
|
+
targetMax: Math.max(...targetTimes),
|
|
259
|
+
targetStd: stddev(targetTimes),
|
|
260
|
+
targetCount: targetTimes.length,
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
return rows;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
function sortRows(
|
|
268
|
+
rows: CompareRow[],
|
|
269
|
+
sort: "name" | "diff" | "winner",
|
|
270
|
+
): CompareRow[] {
|
|
271
|
+
const sorted = [
|
|
272
|
+
...rows,
|
|
273
|
+
];
|
|
274
|
+
switch (sort) {
|
|
275
|
+
case "name":
|
|
276
|
+
sorted.sort((a, b) => a.op.localeCompare(b.op));
|
|
277
|
+
break;
|
|
278
|
+
case "diff":
|
|
279
|
+
sorted.sort((a, b) => Math.abs(1 - b.ratio) - Math.abs(1 - a.ratio));
|
|
280
|
+
break;
|
|
281
|
+
case "winner": {
|
|
282
|
+
const order = {
|
|
283
|
+
"stat-faster": 0,
|
|
284
|
+
"stat-equal": 1,
|
|
285
|
+
"stat-slower": 2,
|
|
286
|
+
};
|
|
287
|
+
sorted.sort(
|
|
288
|
+
(a, b) =>
|
|
289
|
+
order[a.statClass] - order[b.statClass] || a.op.localeCompare(b.op),
|
|
290
|
+
);
|
|
291
|
+
break;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
return sorted;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function filterRows(
|
|
298
|
+
rows: CompareRow[],
|
|
299
|
+
filter: "all" | "faster" | "slower" | "equal",
|
|
300
|
+
): CompareRow[] {
|
|
301
|
+
if (filter === "all") return rows;
|
|
302
|
+
const map = {
|
|
303
|
+
faster: "stat-faster",
|
|
304
|
+
slower: "stat-slower",
|
|
305
|
+
equal: "stat-equal",
|
|
306
|
+
};
|
|
307
|
+
return rows.filter(r => r.statClass === map[filter]);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function buildSummaryHTML(
|
|
311
|
+
rows: CompareRow[],
|
|
312
|
+
baseA: string,
|
|
313
|
+
targetA: string,
|
|
314
|
+
): string {
|
|
315
|
+
const baseWins = rows.filter(r => r.statClass === "stat-faster").length;
|
|
316
|
+
const targetWins = rows.filter(r => r.statClass === "stat-slower").length;
|
|
317
|
+
const equal = rows.filter(r => r.statClass === "stat-equal").length;
|
|
318
|
+
const total = rows.length;
|
|
319
|
+
|
|
320
|
+
let winner = "";
|
|
321
|
+
if (baseWins > targetWins) {
|
|
322
|
+
winner = `<span class="stat-faster">${adapterName(baseA)} wins overall</span>`;
|
|
323
|
+
} else if (targetWins > baseWins) {
|
|
324
|
+
winner = `<span class="stat-slower">${adapterName(targetA)} wins overall</span>`;
|
|
325
|
+
} else {
|
|
326
|
+
winner = `<span class="stat-equal">Tie</span>`;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
return `
|
|
330
|
+
<div id="compare-summary">
|
|
331
|
+
<div class="summary-winner">${winner}</div>
|
|
332
|
+
<div class="summary-stats">
|
|
333
|
+
<span class="summary-stat stat-faster" title="${adapterName(baseA)}">${baseWins} wins</span>
|
|
334
|
+
<span class="summary-stat stat-equal">${equal} equal</span>
|
|
335
|
+
<span class="summary-stat stat-slower" title="${adapterName(targetA)}">${targetWins} wins</span>
|
|
336
|
+
</div>
|
|
337
|
+
<div class="summary-bar">
|
|
338
|
+
<div class="bar-a" style="width: ${total ? (baseWins / total) * 100 : 0}%"></div>
|
|
339
|
+
<div class="bar-equal" style="width: ${total ? (equal / total) * 100 : 0}%"></div>
|
|
340
|
+
<div class="bar-b" style="width: ${total ? (targetWins / total) * 100 : 0}%"></div>
|
|
341
|
+
</div>
|
|
342
|
+
</div>
|
|
343
|
+
`;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
function progressBarHTML(
|
|
347
|
+
value: number,
|
|
348
|
+
maxValue: number,
|
|
349
|
+
cssClass: string,
|
|
350
|
+
): string {
|
|
351
|
+
const pct = maxValue > 0 ? Math.max((value / maxValue) * 100, 2) : 2;
|
|
352
|
+
return `<div class="bar-track"><div class="bar-fill ${cssClass}" style="width: ${pct}%"></div></div>`;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
function tooltipText(row: CompareRow, baseA: string, targetA: string) {
|
|
356
|
+
const baseInfo = `${adapterName(baseA)}: avg ${fmt(row.bAvg)}`;
|
|
357
|
+
const targetInfo = `${adapterName(targetA)}: avg ${fmt(row.tAvg)}`;
|
|
358
|
+
return `${row.titleText} | ${baseInfo} | ${targetInfo}`;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
export function doCompare(
|
|
362
|
+
baseA: string,
|
|
363
|
+
targetA: string,
|
|
364
|
+
basePlatforms: string[] = [],
|
|
365
|
+
targetPlatforms: string[] = [],
|
|
366
|
+
) {
|
|
367
|
+
const container = document.querySelector("#compare-results");
|
|
368
|
+
const summaryContainer = document.querySelector("#compare-summary-wrapper");
|
|
369
|
+
container.innerHTML = "";
|
|
370
|
+
|
|
371
|
+
const baseEntries = filterEntriesByPlatforms(
|
|
372
|
+
state.entries,
|
|
373
|
+
baseA,
|
|
374
|
+
basePlatforms,
|
|
375
|
+
);
|
|
376
|
+
const targetEntries = filterEntriesByPlatforms(
|
|
377
|
+
state.entries,
|
|
378
|
+
targetA,
|
|
379
|
+
targetPlatforms,
|
|
380
|
+
);
|
|
381
|
+
|
|
382
|
+
if (!basePlatforms.length || !targetPlatforms.length) {
|
|
383
|
+
container.innerHTML =
|
|
384
|
+
"<p style='color: var(--pico-muted-color); font-style: italic;'>No platforms selected</p>";
|
|
385
|
+
if (summaryContainer) summaryContainer.innerHTML = "";
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
if (!baseEntries.length || !targetEntries.length) {
|
|
390
|
+
container.innerHTML = "<p>No data available for comparison.</p>";
|
|
391
|
+
if (summaryContainer) summaryContainer.innerHTML = "";
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
const allRows = buildCompareRows(
|
|
396
|
+
baseA,
|
|
397
|
+
targetA,
|
|
398
|
+
basePlatforms,
|
|
399
|
+
targetPlatforms,
|
|
400
|
+
);
|
|
401
|
+
const rows = filterRows(sortRows(allRows, currentSort), currentFilter);
|
|
402
|
+
|
|
403
|
+
if (summaryContainer) {
|
|
404
|
+
summaryContainer.innerHTML = buildSummaryHTML(allRows, baseA, targetA);
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
if (!rows.length) {
|
|
408
|
+
container.innerHTML = "<p>No operations match the current filter.</p>";
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
let html = "";
|
|
413
|
+
for (const row of rows) {
|
|
414
|
+
const cardMax = Math.max(row.bAvg, row.tAvg);
|
|
415
|
+
const tooltip = tooltipText(row, baseA, targetA);
|
|
416
|
+
html += `
|
|
417
|
+
<article class="compare-card" title="${tooltip}">
|
|
418
|
+
<div class="compare-card-header">
|
|
419
|
+
<code>${row.op}</code>
|
|
420
|
+
<span class="compare-badge ${row.statClass}">${row.text}</span>
|
|
421
|
+
</div>
|
|
422
|
+
<div class="compare-bar-row">
|
|
423
|
+
<span class="compare-bar-label time">${fmt(row.bAvg)}</span>
|
|
424
|
+
${progressBarHTML(row.bAvg, cardMax, "bar-a")}
|
|
425
|
+
</div>
|
|
426
|
+
<div class="compare-bar-row">
|
|
427
|
+
<span class="compare-bar-label time">${fmt(row.tAvg)}</span>
|
|
428
|
+
${progressBarHTML(row.tAvg, cardMax, "bar-b")}
|
|
429
|
+
</div>
|
|
430
|
+
</article>
|
|
431
|
+
`;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
container.innerHTML = html;
|
|
435
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { clearCache, loadFromCache, saveToCache } from "./cache";
|
|
2
|
+
import { renderCompare } from "./compare";
|
|
3
|
+
import {
|
|
4
|
+
addLocalResult,
|
|
5
|
+
loadLocalResultsIntoState,
|
|
6
|
+
renderLocalResultsList,
|
|
7
|
+
} from "./local";
|
|
8
|
+
import { renderSummary } from "./summary";
|
|
9
|
+
import { renderTables, initTablesDownload } from "./tables";
|
|
10
|
+
import { ResultFile } from "./types";
|
|
11
|
+
import { normalize, parseEntry } from "./utils";
|
|
12
|
+
import { state } from "./var";
|
|
13
|
+
|
|
14
|
+
async function loadData() {
|
|
15
|
+
const cached = loadFromCache();
|
|
16
|
+
if (cached) {
|
|
17
|
+
state.adapterConfig = cached.adapterConfig;
|
|
18
|
+
state.entries = cached.entries;
|
|
19
|
+
loadLocalResultsIntoState();
|
|
20
|
+
document.querySelector<HTMLDivElement>("#loader").style.display = "none";
|
|
21
|
+
document.querySelector<HTMLDivElement>("#content").style.display = "block";
|
|
22
|
+
renderSummary();
|
|
23
|
+
renderCompare();
|
|
24
|
+
renderTables();
|
|
25
|
+
initTablesDownload();
|
|
26
|
+
renderLocalResultsList();
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
const configRes = await fetch("config.json");
|
|
32
|
+
if (configRes.ok) state.adapterConfig = await configRes.json();
|
|
33
|
+
|
|
34
|
+
const treeRes = await fetch(
|
|
35
|
+
"https://api.github.com/repos/wxn0brP/ValtheraDB-benchmark/git/trees/results?recursive=1",
|
|
36
|
+
);
|
|
37
|
+
const treeData = await treeRes.json();
|
|
38
|
+
|
|
39
|
+
const jsonPaths = treeData.tree
|
|
40
|
+
.filter((item: any) => item.path.endsWith("/result.json"))
|
|
41
|
+
.map((item: any) => item.path);
|
|
42
|
+
|
|
43
|
+
const fetchPromises = jsonPaths.map(async (path: string) => {
|
|
44
|
+
const rawUrl = `https://raw.githubusercontent.com/wxn0brP/ValtheraDB-benchmark/results/${path}`;
|
|
45
|
+
const res = await fetch(rawUrl);
|
|
46
|
+
const data: ResultFile = await res.json();
|
|
47
|
+
|
|
48
|
+
const dir = path.split("/")[0];
|
|
49
|
+
data.results = normalize(data.results);
|
|
50
|
+
return {
|
|
51
|
+
dir,
|
|
52
|
+
info: parseEntry(dir),
|
|
53
|
+
data,
|
|
54
|
+
};
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
state.entries = await Promise.all(fetchPromises);
|
|
58
|
+
loadLocalResultsIntoState();
|
|
59
|
+
saveToCache();
|
|
60
|
+
|
|
61
|
+
document.querySelector<HTMLDivElement>("#loader").style.display = "none";
|
|
62
|
+
document.querySelector<HTMLDivElement>("#content").style.display = "block";
|
|
63
|
+
|
|
64
|
+
renderSummary();
|
|
65
|
+
renderCompare();
|
|
66
|
+
renderTables();
|
|
67
|
+
initTablesDownload();
|
|
68
|
+
renderLocalResultsList();
|
|
69
|
+
} catch (e) {
|
|
70
|
+
console.error("Failed to load data", e);
|
|
71
|
+
document.querySelector("#loader").innerHTML =
|
|
72
|
+
`<p class="danger">Failed to load data. See console for details.</p>`;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const hamburger = document.querySelector<HTMLButtonElement>(".hamburger");
|
|
77
|
+
const navLinks = document.querySelector("#nav-links");
|
|
78
|
+
|
|
79
|
+
hamburger.addEventListener("click", () => {
|
|
80
|
+
const isOpen = navLinks.classList.toggle("open");
|
|
81
|
+
hamburger.classList.toggle("open");
|
|
82
|
+
hamburger.setAttribute("aria-expanded", String(isOpen));
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
navLinks.querySelectorAll("a").forEach(link => {
|
|
86
|
+
link.addEventListener("click", () => {
|
|
87
|
+
navLinks.classList.remove("open");
|
|
88
|
+
hamburger.classList.remove("open");
|
|
89
|
+
hamburger.setAttribute("aria-expanded", "false");
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
document
|
|
94
|
+
.querySelector<HTMLButtonElement>("#clear-cache")
|
|
95
|
+
?.addEventListener("click", clearCache);
|
|
96
|
+
|
|
97
|
+
document
|
|
98
|
+
.querySelector<HTMLButtonElement>("#upload-local-btn")
|
|
99
|
+
?.addEventListener("click", async () => {
|
|
100
|
+
const input = document.querySelector<HTMLInputElement>("#local-file-input");
|
|
101
|
+
if (!input?.files?.length) {
|
|
102
|
+
alert("Please select a file first");
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const file = input.files[0];
|
|
106
|
+
const success = await addLocalResult(file);
|
|
107
|
+
if (success) {
|
|
108
|
+
input.value = "";
|
|
109
|
+
renderLocalResultsList();
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
loadData();
|