opencode/packages/codemode-rust/bench/RESULTS.md

8.7 KiB

Benchmark results

Generated by bench/compare.sh on 2026-11-19. "n/a" means the Rust side could not run the case.

Columns say whether they are a median, a min or a mean. Every speed-up and ratio is computed from medians only; mins and means are shown for spread, never compared.

Environment

  • CPU: Apple M5 Max, 18 cores, 48 GiB RAM, macOS 26.7.1 arm64
  • Reference: anomalyco/opencode 47bf86e198, packages/codemode
  • PsychoScript: 47bf86e198
  • bun 1.4.4; rustc 1.100.0 (0ef1bc386 2026-11-09); cargo 1.100.0 (3acc79c0c 2026-11-05)

(a) Per-case wall time, 11 iterations after one warm-up

Case Reference median ms Reference min ms Rust median ms Rust min ms Median speedup
numeric loop 9.2 6.1 3.9 3.8 2.3x
closure recursion (fib 22) 2.0 1.9 1.4 1.4 1.4x
array callbacks (50k) 36.6 35.8 9.8 9.8 3.7x
promise fan-out (5k) 3.0 2.3 0.9 0.9 3.5x
tool fan-out (1k) ¹ 1.8 1.7 0.4 0.4 4.3x
JSON round-trip 21.9 20.0 10.9 10.6 2.0x
generator iteration 2.2 2.2 1.1 1.1 2.0x
string building 7.8 6.8 2.8 2.7 2.8x
Map/Set ops 5.6 5.5 4.3 4.1 1.3x

¹ tools.echo is an async host function in a Host.namespace on both sides (conformance/reference.ts and conformance/reference.rs); neither validates its input or output.

(b) Cold start: process start to the result of return 1

Implementation Median wall ms (20 runs)
Reference (bun bench/ref/embed.ts) 65.8
Rust (embed example) 1.9

(c) Peak RSS, each case once in a fresh process

Case Reference peak RSS MiB Rust peak RSS MiB
numeric loop 89.3 3.6
closure recursion (fib 22) 81.3 3.6
array callbacks (50k) 107.9 8.0
promise fan-out (5k) 95.5 8.3
tool fan-out (1k) 90.7 5.6
JSON round-trip 122.2 20.1
generator iteration 83.0 3.7
string building 113.6 7.6
Map/Set ops 102.6 10.1

(d) Binary size

Artifact Bytes MiB
Rust embed example, release, stripped 6318616 6.03
bun executable (what you ship otherwise) 88660864 84.55

(e) Perturbed variants, 11 iterations after one warm-up

Each program in bench/variants/ computes the same result as its original, written differently: renamed identifiers, equivalent constants, function expressions and named functions for callbacks, and other loop forms. A variant / original ratio far from the reference's on one side only points at a shape-specific fast path.

Case Reference original median ms Reference variant median ms Reference variant / original Rust original median ms Rust variant median ms Rust variant / original Rust ratio / reference ratio
numeric loop 9.1 6.6 0.72 4.2 4.3 1.04 1.44x
closure recursion (fib 22) 2.0 1.9 0.98 1.4 1.4 0.98 1.00x
array callbacks (50k) 36.8 38.1 1.03 10.0 11.0 1.10 1.06x
promise fan-out (5k) 3.0 2.1 0.69 0.9 1.1 1.23 1.79x
tool fan-out (1k) 1.7 1.4 0.78 0.5 0.5 0.84 1.09x
JSON round-trip 21.1 19.8 0.94 11.0 10.9 0.99 1.06x
generator iteration 3.1 3.0 0.97 1.1 1.1 1.02 1.06x
string building 7.5 7.5 0.99 2.7 3.2 1.15 1.16x
Map/Set ops 5.4 8.1 1.50 4.3 4.7 1.10 0.74x

(f) Plugin event: µs per execute, 2000 runs after 2000 warm-up runs

The conformance reducer (plugin-reducer-*) handling { type: "command", name: "git.status" } with the async tools.git.status host function, through execute once per event. reducer.js is its command path; reducer-padded.js is the whole reducer with eleven more command handlers before the matching one.

Source Bytes Reference median µs Reference min µs Reference mean µs Rust median µs Rust min µs Rust mean µs Median speedup
bench/plugin/reducer.js 226 112.2 92.7 128.3 21.2 19.5 21.4 5.3x
bench/plugin/reducer-padded.js 2957 189.7 153.9 263.1 44.8 41.5 45.2 4.2x

Commands

bash bench/compare.sh  # reference at ../codemode, or CODEMODE_REF=<codemode package dir>
cargo build --release --locked -p psychoscript-bench --bin psychoscript-bench --example embed
# (a)
bun bench/ref/bench.ts --iterations 11 <slug>...
target/release/psychoscript-bench --filter <slug> --iterations 11 --json
# (b) 20 timed runs each after one untimed run, wall time from bash $EPOCHREALTIME (perl's clock without it)
bun bench/ref/embed.ts
target/release/examples/embed
# (c) -l instead of -v on macOS
/usr/bin/time -v bun bench/ref/run-case.ts <slug>
/usr/bin/time -v target/release/psychoscript-bench --filter <slug> --iterations 0
# (d) stat -f %z on macOS
strip -o embed target/release/examples/embed && stat -c %s embed
stat -c %s "$(readlink -f "$(command -v bun)")"
# (e) values must match their originals, on both sides
bun bench/ref/variants.ts --iterations 11 <slug>...
target/release/psychoscript-bench --cases bench/variants --filter <slug> --iterations 11 --json
# (f)
bun bench/ref/plugin.ts --runs 2000 bench/plugin/reducer.js bench/plugin/reducer-padded.js
target/release/psychoscript-bench --plugin --runs 2000 bench/plugin/reducer.js bench/plugin/reducer-padded.js