// The Benchmarks page: players' results from the telemetry server (the baked summary when it doesn't answer) // and the hardware picker (a measurement when there is one, else an estimate from src/estimate.js). import { escape } from "./markdown.js"; import { METRICS, cell, compareRows, format, hardwareHtml, playersHtml } from "./bench.js"; import { estimate, measured, memoryNotes } from "./estimate.js"; import { findCpu, findGpu } from "./hardware.js"; import { setUpMenu, setUpTheme } from "./chrome.js"; const TELEMETRY = "https://telemetry.playhorizon.dev"; const baked = JSON.parse(document.getElementById("bench-data").textContent); let groups = baked.groups || []; async function live() { try { const res = await fetch(`${TELEMETRY}/v1/benchmarks/summary`, { signal: AbortSignal.timeout(3000) }); if (!res.ok) throw new Error(String(res.status)); const summary = await res.json(); if (summary.format !== "horizon-benchmark-summary" || summary.version !== 1 || !Array.isArray(summary.groups)) throw new Error("format"); // Our own rows stay the baked ones; players' come from the server. const players = summary.groups.filter((g) => g.source === "players" && g.installs >= (summary.min_installs || 3)); groups = [...groups.filter((g) => g.source === "us"), ...players]; document.getElementById("players-table").innerHTML = playersHtml({ ...summary, groups: players }); document.querySelector("[data-players-source]").textContent = `Live from the telemetry server, aggregated ${summary.generated.slice(0, 16).replace("T", " ")} UTC.`; render(); } catch { // The baked results stay; the line under the heading already says when they were made. } } // Players' play sessions per hardware class (last 30 days); the section stays hidden until there are some. async function hardware() { try { const res = await fetch(`${TELEMETRY}/v1/aggregate?days=30`, { signal: AbortSignal.timeout(3000) }); if (!res.ok) return; const html = hardwareHtml(await res.json()); if (!html) return; document.getElementById("players-hardware-table").innerHTML = html; document.getElementById("players-hardware").hidden = false; } catch { // Nothing to show. } } const picker = document.getElementById("picker"); const out = document.getElementById("pick-result"); const range = (kind, e) => { if (!e) return "–"; if (e.atLeast) return `at least ${format(kind, e.low)}`; return e.low != null ? `${format(kind, e.low)} to ${format(kind, e.high)}` : format(kind, e.value); }; function sourceBadge(row) { return row.source === "us" ? `Measured by us · ${escape(row.machine)}` : `From ${row.installs} players`; } function measuredTable(h, j) { return `
| Horizon | Java | Horizon against Java | |
|---|---|---|---|
| ${escape(m.label)} | ${cell(m, h)} | ${cell(m, j)} | ${c ? escape(c.text) : ""} |
| Horizon (estimate) | Java (estimate) | |
|---|---|---|
| ${escape(m.label)} | ${range(m.kind, h?.[m.key])} | ${range(m.kind, j?.[m.key])} |
${[h, j].filter(Boolean).map(sourceBadge).join(" ")}
${measuredTable(h, j)}${notesHtml(...[h, j].filter(Boolean).map((row) => memoryNotes(row, gpu, ramGb)))}${ h && h.source === "us" && h.measured ? `` : "" }`; return; } const h = estimate(groups, gpu, cpu, rd, "horizon", { ramGb }); const j = estimate(groups, gpu, cpu, rd, "vanilla", { ramGb }); if (!h && !j) { out.innerHTML = `Nothing measured at render distance ${rd} to estimate from yet.
`; return; } const base = (h || j).base; const f = (h || j).factors; const times = (x) => `${x >= 1 ? x.toFixed(x >= 10 ? 0 : 1) : x.toFixed(2)}x`; out.innerHTML = `Estimate From ${escape(base.source === "us" ? base.machine : `${base.gpu} with ${base.cpu}`)} (${escape(base.gpu)}, ${escape(base.cpu)}): GPU factor ${times(f.gpu)}, CPU factor ${times(f.cpu)}. How
${estimateTable(h, j)}${notesHtml(h?.notes || [], j?.notes || [])}`; } setUpTheme(); setUpMenu(); picker.addEventListener("change", render); render(); live(); hardware();