Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

bench(aot): the same benchmark, on a phone

yhh10b936bdbc46
diff --git a/bench/aot-frame/README.md b/bench/aot-frame/README.md
index 65b17ea79..4f1a585f2 100644
--- a/bench/aot-frame/README.md
+++ b/bench/aot-frame/README.md
@@ -16,10 +16,27 @@ BENCH_ENTITIES=20000 BENCH_FRAMES=300 node bench/aot-frame/frame-bench.mjs
BENCH_REPS=9 node bench/aot-frame/frame-bench.mjs
```
-`build.mjs` emits three things from one source file (`project/src/systems.ts`): the
+`build.mjs` emits four things from one source file (`project/src/systems.ts`): the
compiled twins (`systems.wasm` + `systems.json`, through the real AOT build step) and
-the same file as JavaScript for the interpreted run. One source, two worlds — a
-retyped copy would only ever agree with its own mistakes.
+the same file as JavaScript, twice — once for node, once for the browser. One source,
+two worlds — a retyped copy would only ever agree with its own mistakes.
+
+### On a phone
+
+```sh
+node bench/aot-frame/serve.mjs # prints the URLs it is reachable at
+adb reverse tcp:8788 tcp:8788 # over USB: no Wi-Fi, no firewall hole
+adb shell "am start -a android.intent.action.VIEW -d 'http://127.0.0.1:8788/?entities=5000&reps=3'"
+```
+
+The page runs the same loop (`measure.mjs`) against the same three artifacts a shipped
+web build carries, prints the table on the device, and posts it back to the terminal
+that served it. Quote the URL for the DEVICE's shell — an unquoted `&` there truncates
+the query string and the run silently uses defaults.
+
+The screen must stay on: a browser whose page is not visible stops being scheduled, and
+the run simply never finishes. `adb shell svc power stayon usb` keeps it awake while
+plugged in (and `svc power stayon false` puts it back).
Each configuration runs in its own process, several times, and the **fastest** rep is
reported: noise on a desktop only ever adds time. The spread beside each row is what
@@ -74,14 +91,40 @@ frame's rows are this frame's. Same bench, after that:
where under 83 ns of plumbing the two were indistinguishable. Ratios at 5,000 entities
run 19x (heavy) to 110x (script).
+## On a real phone (2026-08-26)
+
+Xiaomi 24129PN74C — Snapdragon 8 Elite (SM8750), Android 16, Chromium 135 — 5,000
+entities, 400 frames, 200 warmup, 3 reps, over USB with `adb reverse`:
+
+| body | interpreted | compiled | frame |
+|---|---|---|---|
+| thin | 345 ns/entity (1.83 ms/frame) | 3.5 ns (0.124 ms) | 14.8× |
+| thick | 425 ns (2.23 ms) | 7.5 ns (0.144 ms) | 15.5× |
+| heavy | 385 ns (2.03 ms) | 11.1 ns (0.162 ms) | 12.5× |
+| script | 486 ns (2.54 ms) | 2.8 ns (0.121 ms) | 21.1× |
+
+Every checksum matched its interpreted twin.
+
+**Read the first row as a frame budget.** One trivial system over 5,000 entities costs
+**1.7 ms of a 16.7 ms frame** interpreted — 10% of 60fps for three multiply-adds — and
+**0.018 ms** compiled. That is the number this whole road was for.
+
+The phone is 1.6–1.9× slower than the desktop on the interpreted side and **about the
+same on the compiled side** (2.8–11 ns against 2.1–9.4): what is left of a compiled
+system is a memcpy and a wasm call, and those are memory-bound rather than
+core-bound. The shape is the desktop's shape, so nothing about these ratios was an
+artifact of one machine.
+
## What this is NOT
**A no-JIT number, and that is the number AOT exists for.** V8 and JSC compile the
interpreted body to machine code; iOS, WeChat on iOS and QuickJS do not. On those the
interpreted body stops being free and starts costing what Stage 0 measured (154–385×
-for the loop alone), while the compiled body still costs nothing. This machine cannot
-run that half: `node --jitless` has no `WebAssembly` at all, so the engine will not
-boot under it. Run it where a JavaScriptCore is:
+for the loop alone), while the compiled body still costs nothing. **Android does not
+answer this**: its browsers and WebView have a JIT like any desktop's, which is why the
+phone numbers above look like the desktop's. Neither does `node --jitless` — it has no
+`WebAssembly` at all, so the engine will not boot under it. Run it where a
+JavaScriptCore is:
```sh
bun bench/aot-frame/frame-bench.mjs # JSC, JIT
diff --git a/bench/aot-frame/build.mjs b/bench/aot-frame/build.mjs
index 945f9d996..ecd2aa3e1 100644
--- a/bench/aot-frame/build.mjs
+++ b/bench/aot-frame/build.mjs
@@ -84,6 +84,10 @@ async function main() {
if (!existsSync(sdk)) throw new Error(`the SDK node entry is not built: ${sdk}`);
writeFileSync(join(OUT, 'systems.js'),
js.replace(/from\s*["']esengine["']/, `from ${JSON.stringify(pathToFileURL(sdk).href)}`));
+ // The same twin for the browser runner, pointed at the SDK the server
+ // mounts rather than at a file on this disk.
+ writeFileSync(join(OUT, 'systems.web.js'),
+ js.replace(/from\s*["']esengine["']/, "from '/sdk/index.js'"));
console.log(`wrote ${OUT}`);
} finally {
cleanup();
diff --git a/bench/aot-frame/frame-bench.mjs b/bench/aot-frame/frame-bench.mjs
index d611770af..8df5fd050 100644
--- a/bench/aot-frame/frame-bench.mjs
+++ b/bench/aot-frame/frame-bench.mjs
@@ -53,6 +53,9 @@ import { existsSync, readFileSync } from 'node:fs';
import { spawnSync } from 'node:child_process';
import { dirname, join, resolve } from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';
+import { CONFIGS, measure, pct } from './measure.mjs';
+
+const ms = (x) => x.toFixed(3);
const HERE = dirname(fileURLToPath(import.meta.url));
const REPO = resolve(HERE, '..', '..');
@@ -70,20 +73,6 @@ const WARMUP = intEnv('BENCH_WARMUP', 120);
const REPS = intEnv('BENCH_REPS', 5);
const DT = 1 / 60;
-const now = (typeof performance !== 'undefined' && typeof performance.now === 'function')
- ? () => performance.now() : () => Date.now();
-
-/** The same scene for every run: a comparison of two engines needs one workload. */
-function mulberry32(seed) {
- let a = seed >>> 0;
- return () => {
- a |= 0; a = (a + 0x6D2B79F5) | 0;
- let t = Math.imul(a ^ (a >>> 15), 1 | a);
- t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
- return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
- };
-}
-
function detectRuntime() {
if (typeof Bun !== 'undefined') return `bun ${process.versions?.bun ?? '?'} (JSC)`;
if (typeof process !== 'undefined' && process.versions?.node) return `node ${process.versions.node} (V8)`;
@@ -106,88 +95,25 @@ function resolveSdk() {
throw new Error(`no built SDK node entry. Tried:\n ${candidates.join('\n ')}`);
}
-const pct = (sorted, p) => sorted[Math.min(sorted.length - 1, Math.floor((p / 100) * sorted.length))];
-const ms = (x) => x.toFixed(3);
-
-/**
- * One world, N frames, one number per frame. A `body` of null schedules no
- * project system — the idle run. `compiled` installs the twins before anything
- * is spawned, the only moment it can: the rows a twin reads have to be
- * allocated in the memory it reads.
- */
-async function measure(sdk, fixture, wasmDir, body, compiled) {
- const { loadEsengineModule, createHeadlessApp, Transform, Schedule } = sdk;
- const module = await loadEsengineModule(wasmDir);
- const app = createHeadlessApp(module);
- if (compiled) {
- const manifest = JSON.parse(readFileSync(join(BUILD, 'systems.json'), 'utf8'));
- const installed = await app.installCompiledSystems(join(BUILD, 'systems.wasm'), manifest);
- if (installed === 0) throw new Error('the module installed no twins');
- }
-
- const world = app.world;
- const cppRegistry = world.getCppRegistry();
- const rand = mulberry32(0x1234abcd);
- const entities = [];
- for (let i = 0; i < ENTITIES; i++) {
- const e = world.spawn();
- world.insert(e, Transform, { position: { x: (rand() - 0.5) * 2000, y: (rand() - 0.5) * 2000, z: 0 } });
- world.insert(e, fixture.Mover, {
- dx: rand() - 0.5, dy: rand() - 0.5, speed: 40 + rand() * 80, boost: rand() < 0.5 ? 1 : 0,
- });
- if (body === 'script') world.insert(e, fixture.Pos, { x: 0, y: 0, z: 0 });
- entities.push(e);
- }
- const systems = {
- thin: fixture.thinSystem, thick: fixture.thickSystem,
- heavy: fixture.heavySystem, script: fixture.scriptSystem,
- };
- if (body) app.addSystemToSchedule(Schedule.Update, systems[body]);
-
- const step = async () => {
- await app.tick(DT);
- if (cppRegistry) module.transform_update(cppRegistry);
- };
- for (let f = 0; f < WARMUP; f++) await step();
-
- const samples = new Float64Array(FRAMES);
- for (let f = 0; f < FRAMES; f++) {
- const t0 = now();
- await step();
- samples[f] = now() - t0;
- }
-
- // What the frames actually computed. Two runs that disagree here are not two
- // measurements of one thing, and the ratio between them means nothing.
- let checksum = 0;
- for (const e of entities) {
- const p = body === 'script' ? world.get(e, fixture.Pos) : world.get(e, Transform).position;
- checksum += p.x + p.y + p.z;
- }
-
- const sorted = Array.from(samples).sort((a, b) => a - b);
- return { median: pct(sorted, 50), p95: pct(sorted, 95), checksum };
-}
-
-const CONFIGS = [
- { key: 'thin interpreted', body: 'thin', compiled: false },
- { key: 'thin compiled', body: 'thin', compiled: true },
- { key: 'thick interpreted', body: 'thick', compiled: false },
- { key: 'thick compiled', body: 'thick', compiled: true },
- { key: 'heavy interpreted', body: 'heavy', compiled: false },
- { key: 'heavy compiled', body: 'heavy', compiled: true },
- { key: 'script interpreted', body: 'script', compiled: false },
- { key: 'script compiled', body: 'script', compiled: true },
- { key: 'idle scene', body: null, compiled: false },
-];
-
/** One configuration, in this process, reported on stdout for the parent. */
async function child(key) {
const config = CONFIGS.find((c) => c.key === key);
if (!config) throw new Error(`no such configuration: ${key}`);
const sdk = await import(pathToFileURL(resolveSdk()).href);
const fixture = await import(pathToFileURL(join(BUILD, 'systems.js')).href);
- const r = await measure(sdk, fixture, resolveWasmDir(), config.body, config.compiled);
+ const wasmDir = resolveWasmDir();
+ const r = await measure({
+ sdk,
+ fixture,
+ newModule: () => sdk.loadEsengineModule(wasmDir),
+ aot: {
+ wasm: join(BUILD, 'systems.wasm'),
+ manifest: JSON.parse(readFileSync(join(BUILD, 'systems.json'), 'utf8')),
+ },
+ body: config.body,
+ compiled: config.compiled,
+ entities: ENTITIES, frames: FRAMES, warmup: WARMUP,
+ });
console.log(`RESULT ${JSON.stringify(r)}`);
}
diff --git a/bench/aot-frame/measure.mjs b/bench/aot-frame/measure.mjs
new file mode 100644
index 000000000..666f7bd84
--- /dev/null
+++ b/bench/aot-frame/measure.mjs
@@ -0,0 +1,109 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+/**
+ * @file measure.mjs — one world, N frames, one number per frame.
+ *
+ * Shared by both hosts of this benchmark: `frame-bench.mjs` runs it under node
+ * on a desktop, `web/bench.js` runs it in a browser on a phone. What differs
+ * between them is only how an engine module is made, so that is the one thing
+ * passed in — a second copy of the loop would be a second thing to keep honest,
+ * and the two numbers are meant to be comparable.
+ *
+ * No node built-ins here, for the same reason.
+ */
+
+/** The same scene every time: comparing two engines needs one workload. */
+export function mulberry32(seed) {
+ let a = seed >>> 0;
+ return () => {
+ a |= 0; a = (a + 0x6D2B79F5) | 0;
+ let t = Math.imul(a ^ (a >>> 15), 1 | a);
+ t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
+ return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
+ };
+}
+
+export const pct = (sorted, p) => sorted[Math.min(sorted.length - 1, Math.floor((p / 100) * sorted.length))];
+
+const now = (typeof performance !== 'undefined' && typeof performance.now === 'function')
+ ? () => performance.now() : () => Date.now();
+
+/**
+ * `body` of null schedules no project system — the idle run every other one is
+ * read against. `compiled` installs the twins BEFORE anything is spawned, the
+ * only moment it can: the rows a twin reads have to be allocated in the memory
+ * it reads.
+ */
+export async function measure({
+ sdk, fixture, newModule, aot, body, compiled,
+ entities = 5000, frames = 600, warmup = 120, dt = 1 / 60,
+}) {
+ const { createHeadlessApp, Transform, Schedule } = sdk;
+ const module = await newModule();
+ const app = createHeadlessApp(module);
+ if (compiled) {
+ const installed = await app.installCompiledSystems(aot.wasm, aot.manifest);
+ if (installed === 0) throw new Error('the module installed no twins');
+ }
+
+ const world = app.world;
+ const cppRegistry = world.getCppRegistry();
+ const rand = mulberry32(0x1234abcd);
+ const ids = [];
+ for (let i = 0; i < entities; i++) {
+ const e = world.spawn();
+ world.insert(e, Transform, { position: { x: (rand() - 0.5) * 2000, y: (rand() - 0.5) * 2000, z: 0 } });
+ world.insert(e, fixture.Mover, {
+ dx: rand() - 0.5, dy: rand() - 0.5, speed: 40 + rand() * 80, boost: rand() < 0.5 ? 1 : 0,
+ });
+ if (body === 'script') world.insert(e, fixture.Pos, { x: 0, y: 0, z: 0 });
+ ids.push(e);
+ }
+ const systems = {
+ thin: fixture.thinSystem, thick: fixture.thickSystem,
+ heavy: fixture.heavySystem, script: fixture.scriptSystem,
+ };
+ if (body) app.addSystemToSchedule(Schedule.Update, systems[body]);
+
+ const step = async () => {
+ await app.tick(dt);
+ if (cppRegistry) module.transform_update(cppRegistry);
+ };
+ for (let f = 0; f < warmup; f++) await step();
+
+ const samples = new Float64Array(frames);
+ const batch0 = now();
+ for (let f = 0; f < frames; f++) {
+ const t0 = now();
+ await step();
+ samples[f] = now() - t0;
+ }
+ // The whole run divided by its frames, because a browser coarsens
+ // `performance.now()` to about 100us: per-frame samples there quantise to 0
+ // or 0.1 while the total stays exact. A desktop clock has both.
+ const mean = (now() - batch0) / frames;
+
+ // What the frames actually computed. Two runs that disagree here are not two
+ // measurements of one thing, and the ratio between them means nothing.
+ let checksum = 0;
+ for (const e of ids) {
+ const p = body === 'script' ? world.get(e, fixture.Pos) : world.get(e, Transform).position;
+ checksum += p.x + p.y + p.z;
+ }
+
+ const sorted = Array.from(samples).sort((a, b) => a - b);
+ return { median: pct(sorted, 50), mean, p95: pct(sorted, 95), checksum };
+}
+
+/** The configurations both hosts run, in the order they run them. */
+export const CONFIGS = [
+ { key: 'thin interpreted', body: 'thin', compiled: false },
+ { key: 'thin compiled', body: 'thin', compiled: true },
+ { key: 'thick interpreted', body: 'thick', compiled: false },
+ { key: 'thick compiled', body: 'thick', compiled: true },
+ { key: 'heavy interpreted', body: 'heavy', compiled: false },
+ { key: 'heavy compiled', body: 'heavy', compiled: true },
+ { key: 'script interpreted', body: 'script', compiled: false },
+ { key: 'script compiled', body: 'script', compiled: true },
+ { key: 'idle scene', body: null, compiled: false },
+];
diff --git a/bench/aot-frame/serve.mjs b/bench/aot-frame/serve.mjs
new file mode 100644
index 000000000..359796215
--- /dev/null
+++ b/bench/aot-frame/serve.mjs
@@ -0,0 +1,93 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+/**
+ * @file serve.mjs — the browser benchmark, on a LAN address a phone can open.
+ *
+ * Serves the three artifacts a shipped web build carries (the SDK, the engine
+ * wasm, the compiled module) plus the page that drives them, and takes the
+ * result back on POST /result so the run ends up in the terminal that started
+ * it rather than only on the phone's screen.
+ *
+ * No cable and no adb on purpose: a device on the same network is all this
+ * needs, and that is the setup most likely to exist.
+ *
+ * node bench/aot-frame/build.mjs # once, on a machine with emsdk
+ * node bench/aot-frame/serve.mjs # prints the URL to open
+ */
+import { createServer } from 'node:http';
+import { createReadStream, existsSync, statSync } from 'node:fs';
+import { networkInterfaces } from 'node:os';
+import { dirname, extname, join, normalize, resolve } from 'node:path';
+import { fileURLToPath } from 'node:url';
+
+const HERE = dirname(fileURLToPath(import.meta.url));
+const REPO = resolve(HERE, '..', '..');
+const PORT = Number(process.env['PORT'] ?? 8788);
+
+/**
+ * URL prefix → directory. Nothing outside these is reachable, and the last one
+ * is the benchmark's own directory because the page and the desktop runner share
+ * `measure.mjs` — `/web/bench.js` imports it as `../measure.mjs`.
+ */
+const MOUNTS = {
+ '/sdk/': join(REPO, 'sdk', 'dist'),
+ '/wasm/': join(REPO, 'build', 'wasm', 'web'),
+ '/build/': join(HERE, '.build'),
+ '/': HERE,
+};
+
+const TYPES = {
+ '.html': 'text/html', '.js': 'text/javascript', '.mjs': 'text/javascript',
+ '.json': 'application/json', '.wasm': 'application/wasm', '.map': 'application/json',
+};
+
+function resolveFile(urlPath) {
+ let clean = normalize(decodeURIComponent(urlPath.split('?')[0])).replace(/\\/g, '/');
+ if (clean === '/') clean = '/web/index.html';
+ for (const [prefix, dir] of Object.entries(MOUNTS)) {
+ if (!clean.startsWith(prefix)) continue;
+ const rest = clean.slice(prefix.length) || 'index.html';
+ const file = join(dir, rest);
+ // The mount is the boundary: a path that climbs out of it is not served.
+ if (!file.startsWith(dir)) return null;
+ if (existsSync(file) && statSync(file).isFile()) return file;
+ }
+ return null;
+}
+
+const server = createServer((req, res) => {
+ if (req.method === 'POST' && req.url === '/result') {
+ let body = '';
+ req.on('data', (d) => { body += d; });
+ req.on('end', () => {
+ res.writeHead(204).end();
+ console.log(`\n${'='.repeat(72)}\nRESULT ${body}\n${'='.repeat(72)}`);
+ });
+ return;
+ }
+ const file = resolveFile(req.url ?? '/');
+ if (!file) {
+ console.log(`404 ${req.url}`);
+ res.writeHead(404).end('not found');
+ return;
+ }
+ res.writeHead(200, {
+ 'content-type': TYPES[extname(file).toLowerCase()] ?? 'application/octet-stream',
+ // The page fetches nothing cross-origin, but a phone's browser is stricter
+ // about a bare LAN address than a desktop's; this removes the question.
+ 'access-control-allow-origin': '*',
+ 'cache-control': 'no-store',
+ });
+ createReadStream(file).pipe(res);
+});
+
+server.listen(PORT, '0.0.0.0', () => {
+ console.log(`serving ${HERE}`);
+ for (const [name, list] of Object.entries(networkInterfaces())) {
+ for (const i of list ?? []) {
+ if (i.family === 'IPv4' && !i.internal) console.log(` http://${i.address}:${PORT}/ (${name})`);
+ }
+ }
+ console.log(` http://127.0.0.1:${PORT}/ (this machine)`);
+ console.log('waiting for a run…');
+});
diff --git a/bench/aot-frame/web/bench.js b/bench/aot-frame/web/bench.js
new file mode 100644
index 000000000..075c9cd76
--- /dev/null
+++ b/bench/aot-frame/web/bench.js
@@ -0,0 +1,126 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+/**
+ * @file bench.js — the AOT frame benchmark, in a browser, for a real device.
+ *
+ * The desktop runner answers what a compiled system costs on a workstation. This
+ * one answers it on the machine games actually ship to, and it runs the SAME
+ * loop (`measure.mjs`) against the same three artifacts a shipped web build
+ * carries: the engine wasm, the SDK, and the module the AOT step compiled.
+ *
+ * It reports on the page and posts the same JSON back to whoever served it, so a
+ * phone needs no cable and no devtools — open the URL, read the table.
+ *
+ * Reps run in one page rather than one process each (a browser has no second
+ * process to offer), so the fastest rep is what is reported: noise on a phone
+ * only ever adds time, and a thermally throttled rep measured the phone's
+ * temperature.
+ */
+import { CONFIGS, measure, pct } from '../measure.mjs';
+
+const params = new URLSearchParams(location.search);
+const int = (name, def) => {
+ const v = Number(params.get(name));
+ return Number.isFinite(v) && v > 0 ? Math.floor(v) : def;
+};
+const ENTITIES = int('entities', 5000);
+const FRAMES = int('frames', 300);
+const WARMUP = int('warmup', 60);
+const REPS = int('reps', 2);
+
+const out = document.getElementById('out');
+const say = (line) => {
+ out.textContent += `${line}\n`;
+ window.scrollTo(0, document.body.scrollHeight);
+};
+const ms = (x) => x.toFixed(3);
+
+async function main() {
+ say(`entities ${ENTITIES} frames ${FRAMES} (+${WARMUP}) reps ${REPS}`);
+ say(navigator.userAgent);
+ say('-'.repeat(52));
+
+ const sdk = await import('/sdk/index.js');
+ const fixture = await import('/build/systems.web.js');
+ const manifest = await (await fetch('/build/systems.json')).json();
+ const { default: createModule } = await import('/wasm/esengine.js');
+ // One engine for the whole run: each measurement builds its own App on a
+ // fresh Registry, and eighteen wasm heaps is how a phone runs out of memory.
+ const engine = await createModule({
+ locateFile: (p) => `/wasm/${p}`,
+ print: () => {}, printErr: (t) => say(`[wasm] ${t}`),
+ });
+ const newModule = () => engine;
+
+ const runs = new Map(CONFIGS.map((c) => [c.key, []]));
+ for (let rep = 0; rep < REPS; rep++) {
+ for (const c of CONFIGS) {
+ runs.get(c.key).push(await measure({
+ sdk, fixture, newModule,
+ aot: { wasm: '/build/systems.wasm', manifest },
+ body: c.body, compiled: c.compiled,
+ entities: ENTITIES, frames: FRAMES, warmup: WARMUP,
+ }));
+ // Yield to the browser between configurations: a page that never
+ // returns to the event loop is a page the phone may decide to kill.
+ await new Promise((r) => setTimeout(r, 50));
+ }
+ say(`rep ${rep + 1}/${REPS} done`);
+ }
+
+ // The batch mean, not the per-frame median: a browser's clock is too coarse
+ // for one frame of a compiled system (see measure.mjs). Fastest rep, because
+ // a throttled one measured the phone's temperature.
+ const of = (key) => {
+ const means = runs.get(key).map((r) => r.mean).sort((a, b) => a - b);
+ return {
+ median: means[0], hi: means[means.length - 1],
+ p95: pct(runs.get(key).map((r) => r.p95).sort((a, b) => a - b), 50),
+ checksum: runs.get(key)[0].checksum,
+ };
+ };
+
+ const idle = of('idle scene');
+ const table = [];
+ say('config ms/frame slowest the system ns/entity');
+ for (const c of CONFIGS) {
+ const r = of(c.key);
+ const own = c.body ? r.median - idle.median : null;
+ table.push({ key: c.key, median: r.median, p95: r.p95, own, checksum: r.checksum });
+ say(`${c.key.padEnd(20)} ${ms(r.median).padStart(8)} ${ms(r.hi).padStart(8)} `
+ + `${(own === null ? '' : ms(own)).padStart(10)} `
+ + `${c.body ? (own * 1e6 / ENTITIES).toFixed(1) : ''}`);
+ }
+ say('-'.repeat(52));
+ const ratios = {};
+ for (const body of ['thin', 'thick', 'heavy', 'script']) {
+ const i = of(`${body} interpreted`);
+ const c = of(`${body} compiled`);
+ const agree = i.checksum === c.checksum;
+ ratios[body] = {
+ system: (i.median - idle.median) / (c.median - idle.median),
+ frame: i.median / c.median,
+ agree,
+ };
+ say(`${body}: system ${ratios[body].system.toFixed(2)}x frame ${ratios[body].frame.toFixed(2)}x `
+ + `${agree ? 'same result' : 'RESULT MISMATCH'}`);
+ }
+
+ const report = {
+ userAgent: navigator.userAgent,
+ entities: ENTITIES, frames: FRAMES, warmup: WARMUP, reps: REPS,
+ hardwareConcurrency: navigator.hardwareConcurrency ?? null,
+ table, ratios,
+ };
+ try {
+ await fetch('/result', {
+ method: 'POST', headers: { 'content-type': 'application/json' },
+ body: JSON.stringify(report),
+ });
+ say('posted to the server');
+ } catch (e) {
+ say(`could not post: ${e}`);
+ }
+}
+
+main().catch((e) => say(`FAILED: ${e?.stack || e}`));
diff --git a/bench/aot-frame/web/index.html b/bench/aot-frame/web/index.html
new file mode 100644
index 000000000..2d8dc6d0e
--- /dev/null
+++ b/bench/aot-frame/web/index.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+<meta charset="utf-8">
+<meta name="viewport" content="width=device-width, initial-scale=1">
+<title>Estella AOT frame benchmark</title>
+<style>
+ body { margin: 0; padding: 12px; background: #14161a; color: #d8dee9; }
+ h1 { font: 600 15px system-ui, sans-serif; margin: 0 0 8px; color: #88c0d0; }
+ pre { font: 12px/1.45 ui-monospace, Menlo, Consolas, monospace; white-space: pre; margin: 0; }
+</style>
+</head>
+<body>
+<h1>Estella AOT frame benchmark</h1>
+<pre id="out">starting…
+</pre>
+<script type="module" src="/web/bench.js"></script>
+</body>
+</html>