/addlightness-bench -- before/after performance benchmark
Time two runnable commands head-to-head and report whether the difference is
real -- not just noise. This is the measurement half of addlightness; it
does not trim code (/addlightness) and does not measure static weight
(/addlightness-review).
Scope
- Benchmark ONLY. No edits, no weight metrics, no refactoring.
- Input is two commands you can actually run; output is a timing comparison with
a significance verdict.
- If the user has not trimmed anything yet, point them at
/addlightness. If
they want code-weight numbers (LOC/complexity), point them at
/addlightness-review.
Inputs
The user supplies two runnable commands: a before command and an after
command. Read trailing args / the request as exactly that pair.
- If they hand you two snapshot files instead of commands, ask for (or infer)
the command that runs each -- e.g.
node old.js vs node new.js,
python3 before.py vs python3 after.py.
- Both commands must do the same work on the same input -- otherwise the
comparison is meaningless. State the assumption if you have to guess.
- Quote each command so the harness receives it as one argument.
How to run
Call the benchmark harness once:
"${CLAUDE_PLUGIN_ROOT}/scripts/benchmark.sh" \
--runs 10 --warmup 3 \
--before '<before-command>' \
--after '<after-command>'
It uses hyperfine when present and falls back to a date+awk timing loop
when it is not (this plugin assumes neither hyperfine nor any other profiler is
installed, so expect the fallback). It prints one JSON line -- parse that, do
not eyeball stdout. The emitted keys are exactly: before_ms, after_ms,
pct_change (negative = after faster), faster (bool), welch_t,
significant_at_95 (bool), runs, warmup, and tool. The harness does not
compute median/p95/stddev -- do not expect or report those, even under hyperfine.
Reporting
Report a compact table, then a one-line verdict:
| metric |
value |
| before mean (ms) |
before_ms |
| after mean (ms) |
after_ms |
| % change |
pct_change |
| welch t |
welch_t |
| significant at 95% |
significant_at_95 |
- % change (
pct_change) -- negative means faster (after took less time).
State it as "X% faster" / "X% slower" so the sign is unambiguous.
- Significance verdict -- gate every claim on the emitted
significant_at_95
bool. The harness flags significance via a Welch t-test against a df-aware
two-tailed 95% Welch critical value (emitted as t_crit_95; ~2.1-2.3 at the
default N=10), NOT a fixed 1.96 — never recompute the verdict yourself.
- If
significant_at_95 is true -> report the speedup/regression as real.
- If false -> say so plainly: "No statistically significant difference --
the observed delta is within run-to-run noise." Do not dress up a
noise-level delta as a win. A faster-looking mean with
significant_at_95
false is not a result.
Controls
For the numbers to mean anything:
- Same machine, same conditions. Run before/after back-to-back / interleaved,
not at different times of day.
- Identical N and warmup for both commands; discard warmup runs from the
stats.
- Quiesce background load -- close heavy apps, no concurrent builds; CPU
contention dwarfs small deltas.
- Beware subprocess startup variance. Benchmarking
node x.js /
python3 x.py includes interpreter startup, which has large jitter. If the
stddev is on the order of the mean difference, the signal is swamped --
recommend more runs (25-30+) and/or moving the measured work in-process
rather than per-invocation.
- No thermal/load drift. Don't compare a run from an hour ago against a fresh
one -- rerun both together.
What NOT to do
- Never report a single-run number as a benchmark. One run is an anecdote.
- Never claim an improvement without passing the significance gate. No gate,
no win.
- Never compare runs taken hours apart or on different machines -- thermal
state, background load, and CPU governor drift invalidate the comparison.
- Never silently swap the commands' work. If before and after don't compute
the same result, a timing delta is meaningless -- flag it, don't report it.
- Don't trim or edit code here -- that's
/addlightness.
1---2name: addlightness-bench3description: Benchmark before/after code snapshots and report the performance delta with statistical significance. Runs N=10 timed runs (hyperfine if available, else a date+awk fallback) and computes % improvement. Use when the user says "benchmark this", "is it faster", "measure the speedup", "compare before and after", "did the trim help performance", "time these two", or invokes /addlightness-bench. Triggers on /addlightness-bench.4---56# /addlightness-bench -- before/after performance benchmark78Time two runnable commands head-to-head and report whether the difference is9**real** -- not just noise. This is the **measurement** half of addlightness; it10does not trim code (`/addlightness`) and does not measure static weight11(`/addlightness-review`).1213## Scope1415- Benchmark ONLY. No edits, no weight metrics, no refactoring.16- Input is two commands you can actually run; output is a timing comparison with17 a significance verdict.18- If the user has not trimmed anything yet, point them at `/addlightness`. If19 they want code-weight numbers (LOC/complexity), point them at20 `/addlightness-review`.2122## Inputs2324The user supplies **two runnable commands**: a *before* command and an *after*25command. Read trailing args / the request as exactly that pair.2627- If they hand you two snapshot files instead of commands, ask for (or infer)28 the command that runs each -- e.g. `node old.js` vs `node new.js`,29 `python3 before.py` vs `python3 after.py`.30- Both commands must do the **same work** on the **same input** -- otherwise the31 comparison is meaningless. State the assumption if you have to guess.32- Quote each command so the harness receives it as one argument.3334## How to run3536Call the benchmark harness once:3738```bash39"${CLAUDE_PLUGIN_ROOT}/scripts/benchmark.sh" \40 --runs 10 --warmup 3 \41 --before '<before-command>' \42 --after '<after-command>'43```4445It uses `hyperfine` when present and falls back to a `date`+`awk` timing loop46when it is not (this plugin assumes neither hyperfine nor any other profiler is47installed, so expect the fallback). It prints one JSON line -- **parse that**, do48not eyeball stdout. The emitted keys are exactly: `before_ms`, `after_ms`,49`pct_change` (negative = after faster), `faster` (bool), `welch_t`,50`significant_at_95` (bool), `runs`, `warmup`, and `tool`. The harness does not51compute median/p95/stddev -- do not expect or report those, even under hyperfine.5253## Reporting5455Report a compact table, then a one-line verdict:5657| metric | value |58| --- | --- |59| before mean (ms) | `before_ms` |60| after mean (ms) | `after_ms` |61| % change | `pct_change` |62| welch t | `welch_t` |63| significant at 95% | `significant_at_95` |6465- **% change** (`pct_change`) -- negative means *faster* (after took less time).66 State it as "X% faster" / "X% slower" so the sign is unambiguous.67- **Significance verdict** -- gate every claim on the emitted `significant_at_95`68 bool. The harness flags significance via a Welch t-test against a df-aware69 two-tailed 95% Welch critical value (emitted as `t_crit_95`; ~2.1-2.3 at the70 default N=10), NOT a fixed 1.96 — never recompute the verdict yourself.71 - If `significant_at_95` is **true** -> report the speedup/regression as real.72 - If **false** -> say so plainly: *"No statistically significant difference --73 the observed delta is within run-to-run noise."* Do **not** dress up a74 noise-level delta as a win. A faster-looking mean with `significant_at_95`75 false is not a result.7677## Controls7879For the numbers to mean anything:8081- **Same machine, same conditions.** Run before/after back-to-back / interleaved,82 not at different times of day.83- **Identical N and warmup** for both commands; **discard warmup** runs from the84 stats.85- **Quiesce background load** -- close heavy apps, no concurrent builds; CPU86 contention dwarfs small deltas.87- **Beware subprocess startup variance.** Benchmarking `node x.js` /88 `python3 x.py` includes interpreter startup, which has large jitter. If the89 stddev is on the order of the mean difference, the signal is swamped --90 **recommend more runs (25-30+)** and/or moving the measured work in-process91 rather than per-invocation.92- **No thermal/load drift.** Don't compare a run from an hour ago against a fresh93 one -- rerun both together.9495## What NOT to do9697- **Never report a single-run number** as a benchmark. One run is an anecdote.98- **Never claim an improvement without passing the significance gate.** No gate,99 no win.100- **Never compare runs taken hours apart** or on different machines -- thermal101 state, background load, and CPU governor drift invalidate the comparison.102- **Never silently swap the commands' work.** If before and after don't compute103 the same result, a timing delta is meaningless -- flag it, don't report it.104- **Don't trim or edit code here** -- that's `/addlightness`.