Split The code is public; the app answers only to the crew.

`bun run scripts/cost.ts`: what a tick of the simulation costs, and a guard so it stays that way #118

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

scripts/cost.ts answers what one tick of the simulation costs, in the shape measure.ts already set: it steps a seeded ten-player world through the shipped world.update with NOINPUT, warms up 256 ticks, then records each tick's wall clock into a Float64Array and prints ticks sampled, mean, p50, p95, p99, max, the ticks-…

Notes

shipped merged

opened this

scripts/cost.ts answers what one tick of the simulation costs, in the shape measure.ts already set: it steps a seeded ten-player world through the shipped world.update with NO_INPUT, warms up 256 ticks, then records each tick's wall clock into a Float64Array and prints ticks sampled, mean, p50, p95, p99, max, the ticks-per-second the mean implies, and the share of the 15.6 ms a 64 Hz tick is allowed. Flags are --ticks, --seed, --rules, --difficulty, parsed exactly the way measure.ts parses its own — missing or malformed keeps the default — with parseArgs exported and tested. One world exists at a time; a match that ends is replaced outside the timed region so a long sample measures play rather than a scoreboard.

The arithmetic is summarize, a pure function over a list of milliseconds with nearest-rank percentiles and no clock anywhere in its tests — checked on a shuffled 1..100 (p50 50, p95 95, p99 99), on a single value, on the empty list, and on a Float64Array giving the same answer as the plain array. Exactly one assertion in the suite depends on how fast the machine is: 600 sampled ticks must average under 2 ms, roughly fourteen times the measured cost, so a real regression in bots.ts, trace.ts or world.ts fails and a loaded CI box does not. That test runs in about 0.2 s.

Measured here over three runs of the defaults: mean 0.14 ms a tick, p50 0.11, p95 0.29, p99 0.43 — about 7,200 ticks a second, 1% of the tick budget. The one number I did not put weight on is max, which swung between 3 ms and 30 ms run to run; that is the collector and the box, so the README says to read the mean and the percentiles and ignore it rather than pretending it is stable. README.md carries the numbers and the command next to the measure.ts section, and in the command list up top. Nothing under src/ changed; bun test is green at 458 tests.

To try it: bun run scripts/cost.ts, then bun run scripts/cost.ts --ticks 30000 --rules long --difficulty hard for a longer, harder sample.

🤖 Generated with Claude Code

Closes #90

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs