@mark1russell7/rigor-bench 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -5
- package/build/index.d.ts +23 -5
- package/build/index.d.ts.map +1 -1
- package/build/index.js +47 -14
- package/build/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -80,10 +80,12 @@ The option `noiseCap` caps the A/A spread of the run. The spread is the quantile
|
|
|
80
80
|
```ts
|
|
81
81
|
const v = timeVerdict(records, aaRecords, { noiseCap: 0.06 });
|
|
82
82
|
|
|
83
|
-
v.noise; // { spread, cap, noisy }
|
|
83
|
+
v.noise; // { spread, cap, noisy, aaMedian, biased }
|
|
84
84
|
v.reason; // the spread, the cap and the outcome without the cap
|
|
85
85
|
```
|
|
86
86
|
|
|
87
|
+
Since 0.2.0, the noise cap also examines the bias of the A/A arm. An A/A median ratio out of `[exp(-noiseCap), exp(noiseCap)]` gives `cannot decide`. A bias of this size comes from the order or from the arm slots, not from the candidate. With a `spreadLevel` of 0.5 or more, a biased run is also noisy. More than half of its A/A cases are out of the cap. Thus the bias check decides alone only below the level 0.5. The fields `aaMedian` and `biased` keep the facts of the check.
|
|
88
|
+
|
|
87
89
|
The option `pool` gives a band from the A/A records of earlier quiet runs, with a floor. The caller keeps the pool, for example in a file of the repository:
|
|
88
90
|
|
|
89
91
|
```ts
|
|
@@ -107,12 +109,14 @@ For a fixed limit, for example 1.10 against a fixed base, use `limitVerdict`.
|
|
|
107
109
|
|
|
108
110
|
| Outcome | The rule `difference` (the default) | The rule `band` |
|
|
109
111
|
| --- | --- | --- |
|
|
110
|
-
| `
|
|
111
|
-
| `
|
|
112
|
-
| `
|
|
112
|
+
| `same` | The interval is in `[exp(-margin), exp(margin)]`. The default margin is 0.05. The rule examines this outcome first. | The interval is in the band. |
|
|
113
|
+
| `faster` | The whole interval is below 1, and it is not in the margin. | The interval of the median ratio is below the band. |
|
|
114
|
+
| `slower` | The whole interval is above 1, and it is not in the margin. | The interval is above the band. |
|
|
113
115
|
| `cannot decide` | The interval holds 1 and crosses the margin. | The interval crosses an end of the band. |
|
|
114
116
|
|
|
115
|
-
Both rules give `cannot decide` when the A/A arm has fewer than 5 cases, or when the candidate has no cases. With `noiseCap`,
|
|
117
|
+
Both rules give `cannot decide` when the A/A arm has fewer than 5 cases, or when the candidate has no cases. With `noiseCap`, an A/A spread of the run above the cap also gives `cannot decide`. So does an A/A median ratio of the run out of the cap.
|
|
118
|
+
|
|
119
|
+
Since 0.2.0, the rule `difference` examines the margin before 1. An interval in the margin is `same`, also when it is wholly below 1. An example is the interval `[0.96, 0.98]` with the margin 0.05: it is `same`, and 0.1.2 gave `faster`. An interval below 1 that crosses `exp(-margin)` is still `faster`. With the margin 0, each outcome stays the same.
|
|
116
120
|
|
|
117
121
|
## The power test
|
|
118
122
|
|
|
@@ -131,3 +135,5 @@ Both rules give `cannot decide` when the A/A arm has fewer than 5 cases, or when
|
|
|
131
135
|
| `difference` | 20 | 0.71 | 0 | 0.04 |
|
|
132
136
|
|
|
133
137
|
The rule `band` compares an interval with a band of the same noise, so it needs a change of approximately twice that noise. With the kind `case`, it also calls a real speedup `same`. Thus `difference` is the default. Its false rate is near the 5% of a two-sided interval of level 0.95. A change of 7% needs approximately 20 cases for a power of 0.7.
|
|
138
|
+
|
|
139
|
+
Since 0.2.0, `verdictPower` takes `same` as the true outcome of a ratio in the margin of the rule `difference`. The cells of the table stay, because the ratio 0.93 is out of the margin 0.05.
|
package/build/index.d.ts
CHANGED
|
@@ -120,10 +120,14 @@ type VerdictRule = "band" | "difference";
|
|
|
120
120
|
interface VerdictOptions extends BandOptions {
|
|
121
121
|
/** The rule of the verdict. The default is `difference`, from the power test of `verdictPower`. */
|
|
122
122
|
readonly rule?: VerdictRule;
|
|
123
|
-
/**
|
|
123
|
+
/**
|
|
124
|
+
* The half width on a log scale of the ratios that the rule `difference` calls `same`. The default is 0.05.
|
|
125
|
+
* An interval in the margin is `same`, also when it is wholly below 1.
|
|
126
|
+
*/
|
|
124
127
|
readonly margin?: number;
|
|
125
128
|
/**
|
|
126
129
|
* The noise cap on the A/A spread of the run, on a log scale. Above the cap, the outcome is `cannot decide`.
|
|
130
|
+
* The cap also limits the bias of the A/A arm: an A/A median ratio out of `[exp(-noiseCap), exp(noiseCap)]` gives `cannot decide`.
|
|
127
131
|
* The default is no cap.
|
|
128
132
|
*/
|
|
129
133
|
readonly noiseCap?: number;
|
|
@@ -135,13 +139,20 @@ interface VerdictOptions extends BandOptions {
|
|
|
135
139
|
*/
|
|
136
140
|
readonly pool?: PoolOptions;
|
|
137
141
|
}
|
|
138
|
-
/** The noise cap of a verdict: the A/A spread of the run and the cap. */
|
|
142
|
+
/** The noise cap of a verdict: the A/A spread of the run, the A/A median ratio of the run and the cap. */
|
|
139
143
|
interface NoiseCheck {
|
|
140
144
|
/** The A/A spread of the run, or undefined when the A/A arm has no cases. */
|
|
141
145
|
readonly spread: number | undefined;
|
|
142
146
|
readonly cap: number;
|
|
143
147
|
/** This value is `true` when the spread is above the cap, or when the A/A arm has no cases. */
|
|
144
148
|
readonly noisy: boolean;
|
|
149
|
+
/** The median ratio of the A/A cases of the run, or undefined when the A/A arm has no cases. A value far from 1 shows a bias of the order or of the arm slots. */
|
|
150
|
+
readonly aaMedian: number | undefined;
|
|
151
|
+
/**
|
|
152
|
+
* This value is `true` when the A/A median ratio of the run is out of `[exp(-cap), exp(cap)]`.
|
|
153
|
+
* With a spread level of 0.5 or more, a biased run is also noisy. The check decides alone only below that level.
|
|
154
|
+
*/
|
|
155
|
+
readonly biased: boolean;
|
|
145
156
|
}
|
|
146
157
|
/** A time verdict, with the facts that it uses. */
|
|
147
158
|
interface TimeVerdict {
|
|
@@ -171,11 +182,14 @@ interface TimeVerdict {
|
|
|
171
182
|
}
|
|
172
183
|
/**
|
|
173
184
|
* This function gives the time verdict of the candidate arm `b` against the baseline arm `a`.
|
|
174
|
-
* - The rule `difference` gives `
|
|
175
|
-
*
|
|
185
|
+
* - The rule `difference` gives `same` when the interval is in `[exp(-margin), exp(margin)]`. This test comes first, so
|
|
186
|
+
* an interval in the margin and below 1 is `same`, not `faster`.
|
|
187
|
+
* - Out of the margin, the rule `difference` gives `faster` when the whole interval is below 1, and `slower` when it is above 1.
|
|
188
|
+
* With the margin 0, each outcome stays the same as in 0.1.2.
|
|
176
189
|
* - The rule `band` gives `faster` below the band, `slower` above the band, and `same` in the band.
|
|
177
190
|
* - Each other case is `cannot decide`, and so is an A/A arm with too few cases.
|
|
178
191
|
* - With `noiseCap`, an A/A spread of the run above the cap gives `cannot decide`.
|
|
192
|
+
* - With `noiseCap`, an A/A median ratio of the run out of `[exp(-noiseCap), exp(noiseCap)]` also gives `cannot decide`.
|
|
179
193
|
* - With `pool`, the pooled band replaces the band of the A/A arm of the run. The run still needs `minimum` A/A cases.
|
|
180
194
|
*/
|
|
181
195
|
export declare function timeVerdict(candidate: readonly PairedTime[], aa: readonly PairedTime[], options?: VerdictOptions): TimeVerdict;
|
|
@@ -248,7 +262,11 @@ interface PowerOptions {
|
|
|
248
262
|
interface Power {
|
|
249
263
|
readonly trials: number;
|
|
250
264
|
readonly outcomes: Readonly<Record<TimeOutcome, number>>;
|
|
251
|
-
/**
|
|
265
|
+
/**
|
|
266
|
+
* The share of the trials whose outcome is the true one. For the rule `difference`, a ratio in the margin of the verdict has the true outcome `same`.
|
|
267
|
+
* That margin is the larger of `margin` and the noise of the pooled band. The pool is the same in each trial, so each trial has the same margin.
|
|
268
|
+
* Out of that margin, and for the rule `band`, the true outcome is `faster` below 1, `slower` above 1 and `same` at 1.
|
|
269
|
+
*/
|
|
252
270
|
readonly power: number;
|
|
253
271
|
}
|
|
254
272
|
/**
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/paired.ts","../src/verdict.ts","../src/limit.ts","../src/power.ts","../src/rounds.ts"],"mappings":";;KAOY;;UA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;;;;WAKP;;;;;;WAMA;;WAEA;;;;;WAKA,OAAO;;;UAID;;WAEN;WACA;;WAEA;;WAEA;;;;;WAKA;;;UAIM;WACN,SAAS;;WAET;WACA,gBAAgB;WAChB,MAAM;;;;;;;WAON,UAAU;;WAEV,MAAM;;;;;WAKN,YAAY;;WAEZ,OAAO;;WAEP,QAAQ;;;;;;;;;;;;;;wBAeH,YAAY,oBAAoB,cAAc,aAAa,cAAc,UAAS,iBAAsB;;UCjNvG,qBAAqB;;WAE3B;WACA;;WAEA;;;;;;wBAOK,cAAc,kBAAkB,cAAc,iBAAe;;KAcjE;;UAGK,qBAAqB;;WAE3B;;WAEA;;;UAIM,kBAAkB;;WAExB;;WAEA;WACA,SAAS;;;UAIH;WACN,SAAS;;WAET;WACA;WACA,gBAAgB;;WAEhB,MAAM;;;;;;;;;wBAUD,aAAa,oBAAoB,cAAc,aAAa,cAAc,SAAS,eAAe;;UC/DjG;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA,UAAU;;;UAIJ;WACN;WACA,UAAU,SAAS,OAAO;;;;;;WAM1B;;;;;;wBAOK,aAAa,SAAS,eAAe;;UCjCpC;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;;UAIM;WACN,SAAS;;WAET;;WAEA;;;;;;;wBAQK,WAAW,MAAM,SAAS,OAAO,qBAAqB,SAAS,gBAAgB"}
|
package/build/index.js
CHANGED
|
@@ -135,17 +135,20 @@ function poolOf(pool, level) {
|
|
|
135
135
|
}
|
|
136
136
|
/**
|
|
137
137
|
* This function gives the time verdict of the candidate arm `b` against the baseline arm `a`.
|
|
138
|
-
* - The rule `difference` gives `
|
|
139
|
-
*
|
|
138
|
+
* - The rule `difference` gives `same` when the interval is in `[exp(-margin), exp(margin)]`. This test comes first, so
|
|
139
|
+
* an interval in the margin and below 1 is `same`, not `faster`.
|
|
140
|
+
* - Out of the margin, the rule `difference` gives `faster` when the whole interval is below 1, and `slower` when it is above 1.
|
|
141
|
+
* With the margin 0, each outcome stays the same as in 0.1.2.
|
|
140
142
|
* - The rule `band` gives `faster` below the band, `slower` above the band, and `same` in the band.
|
|
141
143
|
* - Each other case is `cannot decide`, and so is an A/A arm with too few cases.
|
|
142
144
|
* - With `noiseCap`, an A/A spread of the run above the cap gives `cannot decide`.
|
|
145
|
+
* - With `noiseCap`, an A/A median ratio of the run out of `[exp(-noiseCap), exp(noiseCap)]` also gives `cannot decide`.
|
|
143
146
|
* - With `pool`, the pooled band replaces the band of the A/A arm of the run. The run still needs `minimum` A/A cases.
|
|
144
147
|
*/
|
|
145
148
|
function timeVerdict(candidate, aa, options = {}) {
|
|
146
149
|
const level = options.spreadLevel ?? .9;
|
|
147
150
|
if (options.noiseCap !== void 0 && !(options.noiseCap >= 0 && Number.isFinite(options.noiseCap))) throw new RangeError(`timeVerdict: the noise cap is a finite number of 0 or more, not ${options.noiseCap}.`);
|
|
148
|
-
const pool =
|
|
151
|
+
const pool = poolFor(options);
|
|
149
152
|
let verdict = ruleVerdict(candidate, aa, options, pool?.band);
|
|
150
153
|
if (pool !== void 0) verdict = {
|
|
151
154
|
...verdict,
|
|
@@ -155,10 +158,13 @@ function timeVerdict(candidate, aa, options = {}) {
|
|
|
155
158
|
const cap = options.noiseCap;
|
|
156
159
|
const aaRatios = caseRatios(aa);
|
|
157
160
|
const spread = aaRatios.length === 0 ? void 0 : spreadOf(aaRatios, level);
|
|
161
|
+
const aaMedian = aaRatios.length === 0 ? void 0 : Math.exp(quantile(aaRatios.map((r) => Math.log(r.ratio)), .5));
|
|
158
162
|
const noise = {
|
|
159
163
|
spread,
|
|
160
164
|
cap,
|
|
161
|
-
noisy: spread === void 0 || spread > cap
|
|
165
|
+
noisy: spread === void 0 || spread > cap,
|
|
166
|
+
aaMedian,
|
|
167
|
+
biased: aaMedian !== void 0 && Math.abs(Math.log(aaMedian)) > cap
|
|
162
168
|
};
|
|
163
169
|
verdict = {
|
|
164
170
|
...verdict,
|
|
@@ -171,10 +177,34 @@ function timeVerdict(candidate, aa, options = {}) {
|
|
|
171
177
|
outcome: "cannot decide",
|
|
172
178
|
reason
|
|
173
179
|
};
|
|
180
|
+
} else if (noise.biased && verdict.band !== void 0) {
|
|
181
|
+
const reason = `The A/A median ratio of the run is ${round$1(aaMedian)}, out of [${round$1(Math.exp(-cap))}, ${round$1(Math.exp(cap))}] of the noise cap ${cap}. Without the cap, the outcome is "${verdict.outcome}".`;
|
|
182
|
+
verdict = {
|
|
183
|
+
...verdict,
|
|
184
|
+
outcome: "cannot decide",
|
|
185
|
+
reason
|
|
186
|
+
};
|
|
174
187
|
}
|
|
175
188
|
}
|
|
176
189
|
return verdict;
|
|
177
190
|
}
|
|
191
|
+
/** This function gives the pooled band and its facts of the options, or undefined without the option `pool`. */
|
|
192
|
+
function poolFor(options) {
|
|
193
|
+
return options.pool === void 0 ? void 0 : poolOf(options.pool, options.spreadLevel ?? .9);
|
|
194
|
+
}
|
|
195
|
+
/** This function gives the margin of the rule `difference`: the larger of `margin` and the noise of the pooled band. It refuses a margin below 0. */
|
|
196
|
+
function marginOf(options, pooled) {
|
|
197
|
+
const given = options.margin ?? .05;
|
|
198
|
+
if (!(given >= 0)) throw new RangeError(`timeVerdict: the margin is 0 or more, not ${given}.`);
|
|
199
|
+
return pooled === void 0 ? given : Math.max(given, pooled.noise);
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* This function gives the margin that the rule `difference` of `timeVerdict` uses with these options. It uses the same code as the verdict.
|
|
203
|
+
* The pooled band comes from the records of the option `pool`, not from the records of the run.
|
|
204
|
+
*/
|
|
205
|
+
function verdictMargin(options = {}) {
|
|
206
|
+
return marginOf(options, poolFor(options)?.band);
|
|
207
|
+
}
|
|
178
208
|
/** This function gives the outcome of the rule. A pooled band replaces the band of the A/A arm, and it widens the margin of the rule `difference`. */
|
|
179
209
|
function ruleVerdict(candidate, aa, options, pooled) {
|
|
180
210
|
const rule = options.rule ?? "difference";
|
|
@@ -213,9 +243,7 @@ function ruleVerdict(candidate, aa, options, pooled) {
|
|
|
213
243
|
})
|
|
214
244
|
};
|
|
215
245
|
if (rule === "difference") {
|
|
216
|
-
const
|
|
217
|
-
if (!(given >= 0)) throw new RangeError(`timeVerdict: the margin is 0 or more, not ${given}.`);
|
|
218
|
-
const margin = pooled === void 0 ? given : Math.max(given, pooled.noise);
|
|
246
|
+
const margin = marginOf(options, pooled);
|
|
219
247
|
const shown = pooled === void 0 ? margin : round$1(margin);
|
|
220
248
|
const logs = cases.map((c) => Math.log(c.ratio));
|
|
221
249
|
const aaLogs = aaRatios.map((c) => Math.log(c.ratio));
|
|
@@ -227,6 +255,12 @@ function ruleVerdict(candidate, aa, options, pooled) {
|
|
|
227
255
|
high: Math.exp(d.high)
|
|
228
256
|
};
|
|
229
257
|
const span = `The interval of the candidate median over the A/A median is [${round$1(interval.low)}, ${round$1(interval.high)}].`;
|
|
258
|
+
if (d.low >= -margin && d.high <= margin) return {
|
|
259
|
+
...facts,
|
|
260
|
+
interval,
|
|
261
|
+
outcome: "same",
|
|
262
|
+
reason: `${span} The interval is in the margin of ${shown}.`
|
|
263
|
+
};
|
|
230
264
|
if (interval.high < 1) return {
|
|
231
265
|
...facts,
|
|
232
266
|
interval,
|
|
@@ -239,12 +273,6 @@ function ruleVerdict(candidate, aa, options, pooled) {
|
|
|
239
273
|
outcome: "slower",
|
|
240
274
|
reason: `${span} The interval is above 1.`
|
|
241
275
|
};
|
|
242
|
-
if (d.low >= -margin && d.high <= margin) return {
|
|
243
|
-
...facts,
|
|
244
|
-
interval,
|
|
245
|
-
outcome: "same",
|
|
246
|
-
reason: `${span} The interval is in the margin of ${shown}.`
|
|
247
|
-
};
|
|
248
276
|
return {
|
|
249
277
|
...facts,
|
|
250
278
|
interval,
|
|
@@ -416,7 +444,7 @@ function verdictPower(options) {
|
|
|
416
444
|
}
|
|
417
445
|
return out;
|
|
418
446
|
};
|
|
419
|
-
const truth = options.ratio
|
|
447
|
+
const truth = trueOutcome(options.ratio, options.verdict);
|
|
420
448
|
const counts = {
|
|
421
449
|
faster: 0,
|
|
422
450
|
slower: 0,
|
|
@@ -435,6 +463,11 @@ function verdictPower(options) {
|
|
|
435
463
|
power: outcomes[truth]
|
|
436
464
|
};
|
|
437
465
|
}
|
|
466
|
+
/** This function gives the true outcome of a ratio. The margin of the rule `difference` comes first, as in `timeVerdict`. */
|
|
467
|
+
function trueOutcome(ratio, verdict = {}) {
|
|
468
|
+
if ((verdict.rule ?? "difference") === "difference" && Math.abs(Math.log(ratio)) <= verdictMargin(verdict)) return "same";
|
|
469
|
+
return ratio < 1 ? "faster" : ratio > 1 ? "slower" : "same";
|
|
470
|
+
}
|
|
438
471
|
// src/rounds.ts
|
|
439
472
|
/**
|
|
440
473
|
* The timed rounds of one case in one process. The two arms first run for a warm-up time. Then the count of calls of
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["round"],"sources":["../src/paired.ts","../src/verdict.ts","../src/limit.ts","../src/power.ts","../src/rounds.ts"],"sourcesContent":["/**\n * The paired-time record of a bench. Each round runs the two arms of a pair on one case, one after the other, in a\n * fresh process. The order turns each round, so a warm cache or a slow start does not always help the same arm.\n */\nimport { median } from \"@mark1russell7/rigor-statistics\";\n\n/** The two arms of a pair. Arm `a` is the baseline, and arm `b` is the candidate. */\nexport type Arm = \"a\" | \"b\";\n\n/** One round of one pair on one case: the times of the two arms in milliseconds, and the arm that ran first. */\nexport interface PairedTime {\n /** The name of the case: one input of the bench. */\n readonly case: string;\n /** The number of the round, a whole number of 0 or more. */\n readonly round: number;\n readonly first: Arm;\n /** The time of the baseline arm, in milliseconds. */\n readonly a: number;\n /** The time of the candidate arm, in milliseconds. */\n readonly b: number;\n}\n\n/**\n * This function gives the arm that runs first in a round. The order turns each round. A case with an odd `offset`\n * starts with arm `b`, so half of the cases start with each arm.\n */\nexport function firstArm(round: number, offset = 0): Arm {\n if (!Number.isSafeInteger(round) || round < 0) throw new RangeError(`firstArm: the round is a whole number of 0 or more, not ${round}.`);\n if (!Number.isSafeInteger(offset)) throw new RangeError(`firstArm: the offset is a whole number, not ${offset}.`);\n return (((round + offset) % 2) + 2) % 2 === 0 ? \"a\" : \"b\";\n}\n\n/** This function examines one record. A time that is not a finite number above 0 is an error. */\nexport function checkPairedTime(record: PairedTime): PairedTime {\n const where = `the record of the case ${JSON.stringify(record.case)}, round ${record.round}`;\n if (typeof record.case !== \"string\" || record.case === \"\") throw new RangeError(\"checkPairedTime: the case is a string that is not empty.\");\n if (!Number.isSafeInteger(record.round) || record.round < 0) throw new RangeError(`checkPairedTime: in ${where}, the round is a whole number of 0 or more.`);\n if (record.first !== \"a\" && record.first !== \"b\") throw new RangeError(`checkPairedTime: in ${where}, the first arm is \"a\" or \"b\", not ${String(record.first)}.`);\n for (const arm of [\"a\", \"b\"] as const) {\n const ms = record[arm];\n if (!(typeof ms === \"number\" && Number.isFinite(ms) && ms > 0)) throw new RangeError(`checkPairedTime: in ${where}, the time of arm ${arm} is a finite number above 0, not ${String(ms)}.`);\n }\n return record;\n}\n\n/** The ratio of one case: the candidate time over the baseline time, over the rounds of the case. */\nexport interface CaseRatio {\n readonly case: string;\n /** The value `exp(median(log(b / a)))` over the rounds. For an odd count of rounds, it is the median of the ratios. */\n readonly ratio: number;\n readonly rounds: number;\n}\n\n/**\n * This function gives the ratio of each case, in the order of the first record of each case.\n * It examines each record. It refuses a case with 2 records of one round.\n * It also refuses a case whose two orders differ in count by more than 1, because that order did not turn each round.\n */\nexport function caseRatios(records: readonly PairedTime[]): CaseRatio[] {\n const cases = new Map<string, PairedTime[]>();\n for (const record of records) {\n checkPairedTime(record);\n const list = cases.get(record.case) ?? [];\n list.push(record);\n cases.set(record.case, list);\n }\n return [...cases].map(([name, list]) => {\n const rounds = new Set(list.map((r) => r.round));\n if (rounds.size !== list.length) throw new RangeError(`caseRatios: the case ${JSON.stringify(name)} has 2 records of one round.`);\n const aFirst = list.filter((r) => r.first === \"a\").length;\n if (Math.abs(2 * aFirst - list.length) > 1) {\n throw new RangeError(`caseRatios: the case ${JSON.stringify(name)} starts with arm a in ${aFirst} of ${list.length} rounds. The order turns each round.`);\n }\n return { case: name, ratio: Math.exp(median(list.map((r) => Math.log(r.b / r.a)))), rounds: list.length };\n });\n}\n","/**\n * The time verdict of a candidate against a baseline, with the noise of an A/A arm. An A/A pair runs the same code in\n * its two arms. Its ratios show how far apart two equal arms come on this machine. A candidate is faster or slower only\n * when its interval is out of that band.\n */\nimport { type BootstrapOptions, type Comparison, type Interval, bootstrapMedian, bootstrapTwo, compareRatios, median, quantile } from \"@mark1russell7/rigor-statistics\";\nimport { type CaseRatio, type PairedTime, caseRatios } from \"./paired.ts\";\n\n/**\n * The two kinds of an A/A band.\n * - The band `case` holds the ratio of one A/A case. It is wide, so it finds only a large change.\n * - The band `median` holds the median ratio of the A/A cases. It has the scale of the median of the candidate.\n */\nexport type BandKind = \"case\" | \"median\";\n\n/** The options of the A/A band. */\nexport interface BandOptions {\n /** The kind of the band. The default is `median`, from the power test of `verdictPower`. */\n readonly kind?: BandKind;\n /** The quantile of the band `case`, or the level of the bootstrap of the band `median`. The default is 0.95. */\n readonly level?: number;\n /** The fewest A/A cases that give a band. The default is 5, the 5-seed rule. */\n readonly minimum?: number;\n /** The bootstrap of the band `median`. The level of the band replaces its level. */\n readonly bootstrap?: BootstrapOptions;\n}\n\n/** The band of the A/A arm: two equal arms come out in this band of ratios. */\nexport interface Band {\n /** The count of the A/A cases. */\n readonly cases: number;\n readonly kind: BandKind;\n /**\n * The half width of the band on a log scale.\n * For the band `case`, it is the `level` quantile of `abs(log(ratio))` over the A/A cases.\n * For the band `median`, it is the larger distance of an end of the bootstrap interval of the A/A median from 0.\n */\n readonly noise: number;\n /** The ends of the band: `exp(-noise)` and `exp(noise)`. */\n readonly low: number;\n readonly high: number;\n /** The median ratio of the A/A cases. A value far from 1 shows a bias of the order or of the arm slots. */\n readonly median: number;\n}\n\n/** This function gives the band of the A/A arm. The band is symmetric on a log scale. It refuses fewer cases than `minimum`. */\nexport function aaBand(aa: readonly PairedTime[], options: BandOptions = {}): Band {\n const ratios = caseRatios(aa);\n const minimum = options.minimum ?? 5;\n if (ratios.length < minimum) throw new RangeError(`aaBand: the A/A arm has ${ratios.length} cases, and a band needs ${minimum} or more.`);\n const logs = ratios.map((r) => Math.log(r.ratio));\n const kind = options.kind ?? \"median\";\n const level = options.level ?? 0.95;\n let noise: number;\n if (kind === \"case\") noise = quantile(logs.map(Math.abs), level);\n else {\n const interval = bootstrapMedian(logs, { ...options.bootstrap, level });\n noise = Math.max(Math.abs(interval.low), Math.abs(interval.high));\n }\n return { cases: ratios.length, kind, noise, low: Math.exp(-noise), high: Math.exp(noise), median: Math.exp(quantile(logs, 0.5)) };\n}\n\n/**\n * This function gives the A/A spread: the `level` quantile of `abs(log(ratio))` over the A/A cases. The default level is 0.9.\n * It refuses an A/A arm with no cases.\n */\nexport function aaSpread(aa: readonly PairedTime[], level = 0.9): number {\n const ratios = caseRatios(aa);\n if (ratios.length === 0) throw new RangeError(\"aaSpread: the A/A arm has no cases.\");\n return spreadOf(ratios, level);\n}\n\nfunction spreadOf(ratios: readonly CaseRatio[], level: number): number {\n return quantile(ratios.map((r) => Math.abs(Math.log(r.ratio))), level);\n}\n\n/** The options of a pooled band: the A/A records of earlier quiet runs, and a floor. The caller keeps the pool. */\nexport interface PoolOptions {\n /** The A/A records of the earlier runs. Give each run its own case names, for example with the run id as a prefix. */\n readonly records: readonly PairedTime[];\n /** The smallest noise of the band, on a log scale. The default is 0. A floor of `Math.log(1.05)` gives at least the band `[1 / 1.05, 1.05]`. */\n readonly floor?: number;\n /** The fewest pooled cases that give a spread. With fewer cases, the noise of the band is the floor. The default is 5. */\n readonly minimum?: number;\n /**\n * The run of a record, for example the id of its CI run. The verdict counts the runs of the pool with it.\n * The cases of one run share one runner, so they are not independent. Many cases from few runs show the noise of few runners.\n */\n readonly run?: (record: PairedTime) => string;\n}\n\n/** The facts of the pooled band of a verdict. */\nexport interface PoolFacts {\n /** The count of the pooled A/A cases. */\n readonly cases: number;\n /** The count of the runs of the pool, from the option `run`. It is undefined without that option. */\n readonly runs: number | undefined;\n /** The A/A spread of the pooled cases, or undefined when the pool has fewer cases than `minimum`. */\n readonly spread: number | undefined;\n readonly floor: number;\n /** This value is `true` when the spread of the pool is larger than the floor, so the spread gives the noise of the band. */\n readonly pooled: boolean;\n}\n\n/**\n * This function gives the pooled band of the kind `case`. Its noise is the larger of the floor and the A/A spread of the pooled records.\n * The spread is the `level` quantile of `abs(log(ratio))`, with the default level 0.9.\n *\n * A band with fewer pooled cases than `minimum` uses the floor alone. A band with no pooled cases has the median 1.\n */\nexport function pooledBand(pool: PoolOptions, level = 0.9): Band {\n return poolOf(pool, level).band;\n}\n\nfunction poolOf(pool: PoolOptions, level: number): { band: Band; facts: PoolFacts } {\n const floor = pool.floor ?? 0;\n const minimum = pool.minimum ?? 5;\n if (!(floor >= 0 && Number.isFinite(floor))) throw new RangeError(`pooledBand: the floor is a finite number of 0 or more, not ${floor}.`);\n if (!Number.isSafeInteger(minimum) || minimum < 1) throw new RangeError(`pooledBand: the minimum is a whole number of 1 or more, not ${minimum}.`);\n const ratios = caseRatios(pool.records);\n const spread = ratios.length >= minimum ? spreadOf(ratios, level) : undefined;\n const noise = Math.max(floor, spread ?? 0);\n const median = ratios.length === 0 ? 1 : Math.exp(quantile(ratios.map((r) => Math.log(r.ratio)), 0.5));\n const band: Band = { cases: ratios.length, kind: \"case\", noise, low: Math.exp(-noise), high: Math.exp(noise), median };\n const runs = pool.run === undefined ? undefined : new Set(pool.records.map(pool.run)).size;\n return { band, facts: { cases: ratios.length, runs, spread, floor, pooled: spread !== undefined && spread > floor } };\n}\n\n/** The four outcomes of a time verdict. The candidate is the arm `b`, so `faster` is a ratio below 1. */\nexport type TimeOutcome = \"faster\" | \"slower\" | \"same\" | \"cannot decide\";\n\n/** The options of a time verdict. The bootstrap gives the interval of the median ratio of the candidate, and the band `median`. */\n/**\n * The two rules of a time verdict.\n * - The rule `band` compares the interval of the median ratio of the candidate with the A/A band.\n * - The rule `difference` compares the interval of the candidate median over the A/A median with 1 and with `margin`.\n */\nexport type VerdictRule = \"band\" | \"difference\";\n\n/** The options of a time verdict. The bootstrap gives each interval of the verdict. */\nexport interface VerdictOptions extends BandOptions {\n /** The rule of the verdict. The default is `difference`, from the power test of `verdictPower`. */\n readonly rule?: VerdictRule;\n /** The half width on a log scale of the ratios that the rule `difference` calls `same`. The default is 0.05. */\n readonly margin?: number;\n /**\n * The noise cap on the A/A spread of the run, on a log scale. Above the cap, the outcome is `cannot decide`.\n * The default is no cap.\n */\n readonly noiseCap?: number;\n /** The quantile of the A/A spread of the noise cap and of the pooled band. The default is 0.9. */\n readonly spreadLevel?: number;\n /**\n * The pooled band. It replaces the band of the A/A arm of the run in the rule `band` and in `comparison`.\n * The rule `difference` uses the larger of `margin` and the noise of the pooled band as its margin. The default is no pool.\n */\n readonly pool?: PoolOptions;\n}\n\n/** The noise cap of a verdict: the A/A spread of the run and the cap. */\nexport interface NoiseCheck {\n /** The A/A spread of the run, or undefined when the A/A arm has no cases. */\n readonly spread: number | undefined;\n readonly cap: number;\n /** This value is `true` when the spread is above the cap, or when the A/A arm has no cases. */\n readonly noisy: boolean;\n}\n\n/** A time verdict, with the facts that it uses. */\nexport interface TimeVerdict {\n readonly outcome: TimeOutcome;\n /** The reason of the outcome, in one sentence. */\n readonly reason: string;\n readonly cases: readonly CaseRatio[];\n readonly rule: VerdictRule;\n /**\n * The interval that the rule compares, or undefined when there are no candidate cases.\n * With too few A/A cases, it is the interval of the median ratio of the candidate.\n * For the rule `band`, it is the bootstrap interval of the median ratio of the candidate.\n * For the rule `difference`, it is the interval of the candidate median ratio over the A/A median ratio.\n */\n readonly interval: Interval | undefined;\n /** The band of the A/A arm, or undefined when the A/A arm has too few cases. */\n readonly band: Band | undefined;\n /**\n * The counts of the cases out of the band, or undefined without a band.\n * The comparison uses the value `1 + log(ratio)` of each case and the noise of the band, so its two sides are the ends of the band.\n */\n readonly comparison: Comparison | undefined;\n /** The facts of the pooled band. The verdict has this field only with the option `pool`. */\n readonly pool?: PoolFacts;\n /** The noise cap. The verdict has this field only with the option `noiseCap`. */\n readonly noise?: NoiseCheck;\n}\n\n/**\n * This function gives the time verdict of the candidate arm `b` against the baseline arm `a`.\n * - The rule `difference` gives `faster` when the whole interval is below 1, and `slower` when it is above 1.\n * It gives `same` when the interval is in `[exp(-margin), exp(margin)]`.\n * - The rule `band` gives `faster` below the band, `slower` above the band, and `same` in the band.\n * - Each other case is `cannot decide`, and so is an A/A arm with too few cases.\n * - With `noiseCap`, an A/A spread of the run above the cap gives `cannot decide`.\n * - With `pool`, the pooled band replaces the band of the A/A arm of the run. The run still needs `minimum` A/A cases.\n */\nexport function timeVerdict(candidate: readonly PairedTime[], aa: readonly PairedTime[], options: VerdictOptions = {}): TimeVerdict {\n const level = options.spreadLevel ?? 0.9;\n if (options.noiseCap !== undefined && !(options.noiseCap >= 0 && Number.isFinite(options.noiseCap))) {\n throw new RangeError(`timeVerdict: the noise cap is a finite number of 0 or more, not ${options.noiseCap}.`);\n }\n const pool = options.pool === undefined ? undefined : poolOf(options.pool, level);\n let verdict = ruleVerdict(candidate, aa, options, pool?.band);\n if (pool !== undefined) verdict = { ...verdict, pool: pool.facts };\n if (options.noiseCap !== undefined) {\n const cap = options.noiseCap;\n const aaRatios = caseRatios(aa);\n const spread = aaRatios.length === 0 ? undefined : spreadOf(aaRatios, level);\n const noise: NoiseCheck = { spread, cap, noisy: spread === undefined || spread > cap };\n verdict = { ...verdict, noise };\n // The early outcomes (no candidate cases, too few A/A cases) keep their reason. Each other outcome gives way to the cap.\n if (noise.noisy && verdict.band !== undefined) {\n const why = spread === undefined ? \"The A/A arm of the run has no cases, so the noise cap has no spread.\" : `The A/A spread of the run is ${round(spread)}, above the noise cap ${cap}.`;\n const reason = `${why} Without the cap, the outcome is \"${verdict.outcome}\".`;\n verdict = { ...verdict, outcome: \"cannot decide\", reason };\n }\n }\n return verdict;\n}\n\n/** This function gives the outcome of the rule. A pooled band replaces the band of the A/A arm, and it widens the margin of the rule `difference`. */\nfunction ruleVerdict(candidate: readonly PairedTime[], aa: readonly PairedTime[], options: VerdictOptions, pooled: Band | undefined): TimeVerdict {\n const rule = options.rule ?? \"difference\";\n const cases = caseRatios(candidate);\n const aaRatios = caseRatios(aa);\n const minimum = options.minimum ?? 5;\n const none = { cases, rule, interval: undefined, band: undefined, comparison: undefined };\n if (cases.length === 0) return { ...none, outcome: \"cannot decide\", reason: \"The candidate has no cases.\" };\n if (aaRatios.length < minimum) {\n const interval = bootstrapMedian(cases.map((c) => c.ratio), options.bootstrap);\n return { ...none, interval, outcome: \"cannot decide\", reason: `The A/A arm has ${aaRatios.length} cases, and a band needs ${minimum} or more.` };\n }\n const band = pooled ?? aaBand(aa, options);\n const comparison = compareRatios(cases.map((c) => 1 + Math.log(c.ratio)), { better: \"lower\", noise: band.noise });\n const facts = { cases, rule, band, comparison };\n if (rule === \"difference\") {\n const given = options.margin ?? 0.05;\n if (!(given >= 0)) throw new RangeError(`timeVerdict: the margin is 0 or more, not ${given}.`);\n const margin = pooled === undefined ? given : Math.max(given, pooled.noise);\n const shown = pooled === undefined ? margin : round(margin);\n const logs = cases.map((c) => Math.log(c.ratio));\n const aaLogs = aaRatios.map((c) => Math.log(c.ratio));\n const d = bootstrapTwo(logs, aaLogs, (x, y) => median(x) - median(y), options.bootstrap);\n const interval: Interval = { ...d, estimate: Math.exp(d.estimate), low: Math.exp(d.low), high: Math.exp(d.high) };\n const span = `The interval of the candidate median over the A/A median is [${round(interval.low)}, ${round(interval.high)}].`;\n if (interval.high < 1) return { ...facts, interval, outcome: \"faster\", reason: `${span} The interval is below 1.` };\n if (interval.low > 1) return { ...facts, interval, outcome: \"slower\", reason: `${span} The interval is above 1.` };\n if (d.low >= -margin && d.high <= margin) return { ...facts, interval, outcome: \"same\", reason: `${span} The interval is in the margin of ${shown}.` };\n return { ...facts, interval, outcome: \"cannot decide\", reason: `${span} The interval holds 1 and crosses the margin of ${shown}.` };\n }\n const interval = bootstrapMedian(cases.map((c) => c.ratio), options.bootstrap);\n const span = `The interval of the median ratio is [${round(interval.low)}, ${round(interval.high)}], and the A/A band is [${round(band.low)}, ${round(band.high)}].`;\n if (interval.high < band.low) return { ...facts, interval, outcome: \"faster\", reason: `${span} The interval is below the band.` };\n if (interval.low > band.high) return { ...facts, interval, outcome: \"slower\", reason: `${span} The interval is above the band.` };\n if (interval.low >= band.low && interval.high <= band.high) return { ...facts, interval, outcome: \"same\", reason: `${span} The interval is in the band.` };\n return { ...facts, interval, outcome: \"cannot decide\", reason: `${span} The interval crosses an end of the band.` };\n}\n\nfunction round(x: number): number {\n return Math.round(x * 10_000) / 10_000;\n}\n","/**\n * The limit verdict of a bench: is the ratio of each case at most a limit? For example, the claim \"the new code takes at most\n * 2 times the time of the old code\" needs it. The time verdict compares only with 1.\n */\nimport { medianInterval } from \"@mark1russell7/rigor-statistics\";\nimport { type CaseRatio, type PairedTime, caseRatios } from \"./paired.ts\";\nimport { type Band, type BandOptions, aaBand } from \"./verdict.ts\";\n\n/** The ratio of one case with the interval of its median over the rounds. */\nexport interface CaseInterval extends CaseRatio {\n /** The ends of the interval: `exp` of `medianInterval` over the values `log(b / a)` of the rounds. */\n readonly low: number;\n readonly high: number;\n /** The coverage of the interval. It is at least the level. */\n readonly coverage: number;\n}\n\n/**\n * This function gives the ratio of each case with a distribution-free interval of its median, in the order of\n * `caseRatios`. It needs enough rounds for the level: 6 rounds or more for the level 0.95.\n */\nexport function caseIntervals(records: readonly PairedTime[], level = 0.95): CaseInterval[] {\n const logs = new Map<string, number[]>();\n for (const r of records) {\n const list = logs.get(r.case) ?? [];\n list.push(Math.log(r.b / r.a));\n logs.set(r.case, list);\n }\n return caseRatios(records).map((c) => {\n const interval = medianInterval(logs.get(c.case)!, level);\n return { ...c, low: Math.exp(interval.low), high: Math.exp(interval.high), coverage: interval.coverage };\n });\n}\n\n/** The three outcomes of a limit verdict. */\nexport type LimitOutcome = \"within\" | \"beyond\" | \"cannot decide\";\n\n/** The options of a limit verdict. */\nexport interface LimitOptions extends BandOptions {\n /** The largest ratio `b / a` that the claim permits, for example 2. */\n readonly limit: number;\n /** The level of the interval of each case. The default is 0.95. */\n readonly caseLevel?: number;\n}\n\n/** The verdict of one case against the limit. */\nexport interface CaseLimit extends CaseInterval {\n /** The high end of the interval of the case, times the high end of the A/A band. */\n readonly bound: number;\n /** The low end of the interval of the case, times the low end of the A/A band. */\n readonly floor: number;\n readonly outcome: LimitOutcome;\n}\n\n/** A limit verdict, with the facts that it uses. */\nexport interface LimitVerdict {\n readonly outcome: LimitOutcome;\n /** The reason of the outcome, in one sentence. */\n readonly reason: string;\n readonly limit: number;\n readonly cases: readonly CaseLimit[];\n /** The band of the A/A arm, or undefined when the A/A arm has too few cases. */\n readonly band: Band | undefined;\n}\n\n/**\n * This function gives the verdict of the claim \"the ratio `b / a` of each case is at most `limit`\". The A/A band widens\n * the interval of each case: the bound is the high end times the high end of the band.\n * - A case is `within` when its bound is at most the limit, and `beyond` when its floor is above the limit.\n * - The verdict is `beyond` when a case is `beyond`, and `within` when each case is `within`.\n * - Each other verdict is `cannot decide`, and so is an A/A arm with too few cases or a candidate with no cases.\n */\nexport function limitVerdict(candidate: readonly PairedTime[], aa: readonly PairedTime[], options: LimitOptions): LimitVerdict {\n const { limit } = options;\n if (!(limit > 0 && Number.isFinite(limit))) throw new RangeError(`limitVerdict: the limit is a finite number above 0, not ${limit}.`);\n const intervals = caseIntervals(candidate, options.caseLevel);\n const minimum = options.minimum ?? 5;\n if (intervals.length === 0) return { outcome: \"cannot decide\", reason: \"The candidate has no cases.\", limit, cases: [], band: undefined };\n const aaCount = caseRatios(aa).length;\n if (aaCount < minimum) {\n const cases = intervals.map((c) => ({ ...c, bound: c.high, floor: c.low, outcome: \"cannot decide\" as const }));\n return { outcome: \"cannot decide\", reason: `The A/A arm has ${aaCount} cases, and a band needs ${minimum} or more.`, limit, cases, band: undefined };\n }\n const band = aaBand(aa, options);\n const cases = intervals.map((c): CaseLimit => {\n const bound = c.high * band.high;\n const floor = c.low * band.low;\n const outcome: LimitOutcome = bound <= limit ? \"within\" : floor > limit ? \"beyond\" : \"cannot decide\";\n return { ...c, bound, floor, outcome };\n });\n const top = cases.reduce((a, b) => (b.bound > a.bound ? b : a));\n const beyond = cases.filter((c) => c.outcome === \"beyond\");\n if (beyond.length > 0) {\n return { outcome: \"beyond\", reason: `${beyond.length} of ${cases.length} cases are above the limit ${limit}, the first is ${JSON.stringify(beyond[0]!.case)}.`, limit, cases, band };\n }\n if (cases.every((c) => c.outcome === \"within\")) {\n return { outcome: \"within\", reason: `The largest bound is ${round(top.bound)} in the case ${JSON.stringify(top.case)}, and it is at most the limit ${limit}.`, limit, cases, band };\n }\n return { outcome: \"cannot decide\", reason: `The bound of the case ${JSON.stringify(top.case)} is ${round(top.bound)}, above the limit ${limit}, and its floor is not above it.`, limit, cases, band };\n}\n\nfunction round(x: number): number {\n return Math.round(x * 10_000) / 10_000;\n}\n","/**\n * The power test of a time verdict. It draws seeded benches with a known speedup and counts the verdicts that find it.\n * It also draws benches with equal arms and counts the false verdicts.\n */\nimport { random } from \"@mark1russell7/rigor-generators\";\nimport { firstArm, type PairedTime } from \"./paired.ts\";\nimport { type TimeOutcome, type VerdictOptions, timeVerdict } from \"./verdict.ts\";\n\n/** The options of a power test. */\nexport interface PowerOptions {\n /** The count of the cases of the candidate and of the A/A arm. */\n readonly cases: number;\n /** The count of the rounds of each case. The default is 5. */\n readonly rounds?: number;\n /** The true ratio of the candidate time to the baseline time, for example 0.93 for a speedup of 7%. */\n readonly ratio: number;\n /** The standard deviation of the log time of one arm in one round. The default is 0.1. */\n readonly sigma?: number;\n /** The count of the seeded benches. The default is 200. */\n readonly trials?: number;\n /** The seed of the draws. The default is 1. */\n readonly seed?: number | string;\n /** The options of the verdict of each bench. */\n readonly verdict?: VerdictOptions;\n}\n\n/** The result of a power test: the share of each outcome over the trials. */\nexport interface Power {\n readonly trials: number;\n readonly outcomes: Readonly<Record<TimeOutcome, number>>;\n /** The share of the trials whose outcome is the true one: `faster` for a ratio below 1, `slower` above 1, `same` at 1. */\n readonly power: number;\n}\n\n/**\n * This function draws `trials` benches and gives the share of each verdict. Each case has its own log scale.\n * Each arm of each round adds a normal noise of `sigma` to the log time.\n */\nexport function verdictPower(options: PowerOptions): Power {\n const rounds = options.rounds ?? 5;\n const sigma = options.sigma ?? 0.1;\n const trials = options.trials ?? 200;\n if (!Number.isSafeInteger(options.cases) || options.cases < 1) throw new RangeError(`verdictPower: cases is a whole number of 1 or more, not ${options.cases}.`);\n if (!(options.ratio > 0 && Number.isFinite(options.ratio))) throw new RangeError(`verdictPower: the ratio is a finite number above 0, not ${options.ratio}.`);\n const r = random(options.seed ?? 1);\n const bench = (ratio: number, prefix: string): PairedTime[] => {\n const out: PairedTime[] = [];\n for (let c = 0; c < options.cases; c++) {\n const scale = 10 * Math.exp(r.normal());\n for (let round = 0; round < rounds; round++) {\n const a = scale * Math.exp(r.normal(0, sigma));\n const b = scale * ratio * Math.exp(r.normal(0, sigma));\n out.push({ case: `${prefix}${c}`, round, first: firstArm(round, c), a, b });\n }\n }\n return out;\n };\n const truth: TimeOutcome = options.ratio < 1 ? \"faster\" : options.ratio > 1 ? \"slower\" : \"same\";\n const counts: Record<TimeOutcome, number> = { faster: 0, slower: 0, same: 0, \"cannot decide\": 0 };\n for (let t = 0; t < trials; t++) {\n const aa = bench(1, \"aa\");\n const candidate = bench(options.ratio, \"c\");\n counts[timeVerdict(candidate, aa, options.verdict).outcome]++;\n }\n const outcomes = Object.fromEntries(Object.entries(counts).map(([k, n]) => [k, n / trials])) as Record<TimeOutcome, number>;\n return { trials, outcomes, power: outcomes[truth] };\n}\n","/**\n * The timed rounds of one case in one process. The two arms first run for a warm-up time. Then the count of calls of\n * one batch grows until a batch of arm `a` takes the target time. Each round times one batch of each arm, in the order\n * of `firstArm`. Start this function in a fresh process for each case.\n */\nimport { performance } from \"node:perf_hooks\";\nimport { type Arm, type PairedTime, firstArm } from \"./paired.ts\";\n\n/** The options of the timed rounds of one case. */\nexport interface RoundsOptions {\n /** The name of the case. */\n readonly case: string;\n /** The count of the rounds. */\n readonly rounds: number;\n /** The offset of `firstArm`: give the index of the case, so half of the cases start with each arm. The default is 0. */\n readonly offset?: number;\n /** The least time in milliseconds of one batch of arm `a`. The default is 10. */\n readonly targetMs?: number;\n /** The time in milliseconds of the warm-up of the two arms. The default is 1000. */\n readonly warmMs?: number;\n /** The clock in milliseconds. The default is `performance.now`. */\n readonly now?: () => number;\n}\n\n/** The result of the timed rounds of one case. */\nexport interface Rounds {\n readonly records: PairedTime[];\n /** The count of calls of each arm in one batch. */\n readonly count: number;\n /** The sum of the numbers that the arms gave. The engine cannot remove the work of a call, because this sum uses it. */\n readonly sink: number;\n}\n\n/**\n * This function times the arms `a` and `b` of one case, and gives one `PairedTime` record for each round. The time of\n * a record is the time of one batch, in milliseconds. Each call of an arm gives a number, and the sum of these numbers\n * keeps the work.\n */\nexport function timeRounds(arms: Readonly<Record<Arm, () => number>>, options: RoundsOptions): Rounds {\n const { rounds } = options;\n const offset = options.offset ?? 0;\n const targetMs = options.targetMs ?? 10;\n const warmMs = options.warmMs ?? 1000;\n const now = options.now ?? (() => performance.now());\n if (!Number.isSafeInteger(rounds) || rounds < 1) throw new RangeError(`timeRounds: the rounds are a whole number of 1 or more, not ${rounds}.`);\n if (!Number.isSafeInteger(offset)) throw new RangeError(`timeRounds: the offset is a whole number, not ${offset}.`);\n if (!(targetMs > 0) || !(warmMs >= 0)) throw new RangeError(\"timeRounds: the target time is above 0, and the warm-up time is 0 or more.\");\n let sink = 0;\n const batch = (arm: Arm, count: number): number => {\n const run = arms[arm];\n const start = now();\n for (let i = 0; i < count; i++) sink += run();\n return now() - start;\n };\n let count = 1;\n const warmUntil = now() + warmMs;\n while (now() < warmUntil) {\n if (batch(\"a\", count) < targetMs / 4) count *= 2;\n batch(\"b\", count);\n }\n while (batch(\"a\", count) < targetMs) count *= 2;\n const records: PairedTime[] = [];\n for (let round = 0; round < rounds; round++) {\n const first = firstArm(round, offset);\n const second: Arm = first === \"a\" ? \"b\" : \"a\";\n const times = { [first]: batch(first, count), [second]: batch(second, count) } as Record<Arm, number>;\n records.push({ case: options.case, round, first, a: times.a, b: times.b });\n }\n return { records, count, sink };\n}\n"],"mappings":";;;;;;;;;;;;AA0BA,SAAgB,SAAS,OAAe,SAAS,GAAQ;CACvD,IAAI,CAAC,OAAO,cAAc,KAAK,KAAK,QAAQ,GAAG,MAAM,IAAI,WAAW,2DAA2D,MAAM,EAAE;CACvI,IAAI,CAAC,OAAO,cAAc,MAAM,GAAG,MAAM,IAAI,WAAW,+CAA+C,OAAO,EAAE;CAChH,SAAU,QAAQ,UAAU,IAAK,KAAK,MAAM,IAAI,MAAM;AACxD;;AAGA,SAAgB,gBAAgB,QAAgC;CAC9D,MAAM,QAAQ,0BAA0B,KAAK,UAAU,OAAO,IAAI,EAAE,UAAU,OAAO;CACrF,IAAI,OAAO,OAAO,SAAS,YAAY,OAAO,SAAS,IAAI,MAAM,IAAI,WAAW,0DAA0D;CAC1I,IAAI,CAAC,OAAO,cAAc,OAAO,KAAK,KAAK,OAAO,QAAQ,GAAG,MAAM,IAAI,WAAW,uBAAuB,MAAM,4CAA4C;CAC3J,IAAI,OAAO,UAAU,OAAO,OAAO,UAAU,KAAK,MAAM,IAAI,WAAW,uBAAuB,MAAM,qCAAqC,OAAO,OAAO,KAAK,EAAE,EAAE;CAChK,KAAK,MAAM,OAAO,CAAC,KAAK,GAAG,GAAY;EACrC,MAAM,KAAK,OAAO;EAClB,IAAI,EAAE,OAAO,OAAO,YAAY,OAAO,SAAS,EAAE,KAAK,KAAK,IAAI,MAAM,IAAI,WAAW,uBAAuB,MAAM,oBAAoB,IAAI,mCAAmC,OAAO,EAAE,EAAE,EAAE;CAC5L;CACA,OAAO;AACT;;;;;;AAeA,SAAgB,WAAW,SAA6C;CACtE,MAAM,wBAAQ,IAAI,I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AAQ,SAAS,OAAO,MAAM;EACpC,MAAM,SAAc,UAAU,MAAM,MAAM;EAC1C,MAAM,QAAQ;IAAG,QAAQ,MAAM,OAAO,KAAK;IAAI,SAAS,MAAM,QAAQ,KAAK;EAAE;EAC7E,QAAQ,KAAK;GAAE,MAAM,QAAQ;GAAM;GAAO;GAAO,GAAG,MAAM;GAAG,GAAG,MAAM;EAAE,CAAC;CAC3E;CACA,OAAO;EAAE;EAAS;EAAO;CAAK;AAChC"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["round"],"sources":["../src/paired.ts","../src/verdict.ts","../src/limit.ts","../src/power.ts","../src/rounds.ts"],"sourcesContent":["/**\n * The paired-time record of a bench. Each round runs the two arms of a pair on one case, one after the other, in a\n * fresh process. The order turns each round, so a warm cache or a slow start does not always help the same arm.\n */\nimport { median } from \"@mark1russell7/rigor-statistics\";\n\n/** The two arms of a pair. Arm `a` is the baseline, and arm `b` is the candidate. */\nexport type Arm = \"a\" | \"b\";\n\n/** One round of one pair on one case: the times of the two arms in milliseconds, and the arm that ran first. */\nexport interface PairedTime {\n /** The name of the case: one input of the bench. */\n readonly case: string;\n /** The number of the round, a whole number of 0 or more. */\n readonly round: number;\n readonly first: Arm;\n /** The time of the baseline arm, in milliseconds. */\n readonly a: number;\n /** The time of the candidate arm, in milliseconds. */\n readonly b: number;\n}\n\n/**\n * This function gives the arm that runs first in a round. The order turns each round. A case with an odd `offset`\n * starts with arm `b`, so half of the cases start with each arm.\n */\nexport function firstArm(round: number, offset = 0): Arm {\n if (!Number.isSafeInteger(round) || round < 0) throw new RangeError(`firstArm: the round is a whole number of 0 or more, not ${round}.`);\n if (!Number.isSafeInteger(offset)) throw new RangeError(`firstArm: the offset is a whole number, not ${offset}.`);\n return (((round + offset) % 2) + 2) % 2 === 0 ? \"a\" : \"b\";\n}\n\n/** This function examines one record. A time that is not a finite number above 0 is an error. */\nexport function checkPairedTime(record: PairedTime): PairedTime {\n const where = `the record of the case ${JSON.stringify(record.case)}, round ${record.round}`;\n if (typeof record.case !== \"string\" || record.case === \"\") throw new RangeError(\"checkPairedTime: the case is a string that is not empty.\");\n if (!Number.isSafeInteger(record.round) || record.round < 0) throw new RangeError(`checkPairedTime: in ${where}, the round is a whole number of 0 or more.`);\n if (record.first !== \"a\" && record.first !== \"b\") throw new RangeError(`checkPairedTime: in ${where}, the first arm is \"a\" or \"b\", not ${String(record.first)}.`);\n for (const arm of [\"a\", \"b\"] as const) {\n const ms = record[arm];\n if (!(typeof ms === \"number\" && Number.isFinite(ms) && ms > 0)) throw new RangeError(`checkPairedTime: in ${where}, the time of arm ${arm} is a finite number above 0, not ${String(ms)}.`);\n }\n return record;\n}\n\n/** The ratio of one case: the candidate time over the baseline time, over the rounds of the case. */\nexport interface CaseRatio {\n readonly case: string;\n /** The value `exp(median(log(b / a)))` over the rounds. For an odd count of rounds, it is the median of the ratios. */\n readonly ratio: number;\n readonly rounds: number;\n}\n\n/**\n * This function gives the ratio of each case, in the order of the first record of each case.\n * It examines each record. It refuses a case with 2 records of one round.\n * It also refuses a case whose two orders differ in count by more than 1, because that order did not turn each round.\n */\nexport function caseRatios(records: readonly PairedTime[]): CaseRatio[] {\n const cases = new Map<string, PairedTime[]>();\n for (const record of records) {\n checkPairedTime(record);\n const list = cases.get(record.case) ?? [];\n list.push(record);\n cases.set(record.case, list);\n }\n return [...cases].map(([name, list]) => {\n const rounds = new Set(list.map((r) => r.round));\n if (rounds.size !== list.length) throw new RangeError(`caseRatios: the case ${JSON.stringify(name)} has 2 records of one round.`);\n const aFirst = list.filter((r) => r.first === \"a\").length;\n if (Math.abs(2 * aFirst - list.length) > 1) {\n throw new RangeError(`caseRatios: the case ${JSON.stringify(name)} starts with arm a in ${aFirst} of ${list.length} rounds. The order turns each round.`);\n }\n return { case: name, ratio: Math.exp(median(list.map((r) => Math.log(r.b / r.a)))), rounds: list.length };\n });\n}\n","/**\n * The time verdict of a candidate against a baseline, with the noise of an A/A arm. An A/A pair runs the same code in\n * its two arms. Its ratios show how far apart two equal arms come on this machine. A candidate is faster or slower only\n * when its interval is out of that band.\n */\nimport { type BootstrapOptions, type Comparison, type Interval, bootstrapMedian, bootstrapTwo, compareRatios, median, quantile } from \"@mark1russell7/rigor-statistics\";\nimport { type CaseRatio, type PairedTime, caseRatios } from \"./paired.ts\";\n\n/**\n * The two kinds of an A/A band.\n * - The band `case` holds the ratio of one A/A case. It is wide, so it finds only a large change.\n * - The band `median` holds the median ratio of the A/A cases. It has the scale of the median of the candidate.\n */\nexport type BandKind = \"case\" | \"median\";\n\n/** The options of the A/A band. */\nexport interface BandOptions {\n /** The kind of the band. The default is `median`, from the power test of `verdictPower`. */\n readonly kind?: BandKind;\n /** The quantile of the band `case`, or the level of the bootstrap of the band `median`. The default is 0.95. */\n readonly level?: number;\n /** The fewest A/A cases that give a band. The default is 5, the 5-seed rule. */\n readonly minimum?: number;\n /** The bootstrap of the band `median`. The level of the band replaces its level. */\n readonly bootstrap?: BootstrapOptions;\n}\n\n/** The band of the A/A arm: two equal arms come out in this band of ratios. */\nexport interface Band {\n /** The count of the A/A cases. */\n readonly cases: number;\n readonly kind: BandKind;\n /**\n * The half width of the band on a log scale.\n * For the band `case`, it is the `level` quantile of `abs(log(ratio))` over the A/A cases.\n * For the band `median`, it is the larger distance of an end of the bootstrap interval of the A/A median from 0.\n */\n readonly noise: number;\n /** The ends of the band: `exp(-noise)` and `exp(noise)`. */\n readonly low: number;\n readonly high: number;\n /** The median ratio of the A/A cases. A value far from 1 shows a bias of the order or of the arm slots. */\n readonly median: number;\n}\n\n/** This function gives the band of the A/A arm. The band is symmetric on a log scale. It refuses fewer cases than `minimum`. */\nexport function aaBand(aa: readonly PairedTime[], options: BandOptions = {}): Band {\n const ratios = caseRatios(aa);\n const minimum = options.minimum ?? 5;\n if (ratios.length < minimum) throw new RangeError(`aaBand: the A/A arm has ${ratios.length} cases, and a band needs ${minimum} or more.`);\n const logs = ratios.map((r) => Math.log(r.ratio));\n const kind = options.kind ?? \"median\";\n const level = options.level ?? 0.95;\n let noise: number;\n if (kind === \"case\") noise = quantile(logs.map(Math.abs), level);\n else {\n const interval = bootstrapMedian(logs, { ...options.bootstrap, level });\n noise = Math.max(Math.abs(interval.low), Math.abs(interval.high));\n }\n return { cases: ratios.length, kind, noise, low: Math.exp(-noise), high: Math.exp(noise), median: Math.exp(quantile(logs, 0.5)) };\n}\n\n/**\n * This function gives the A/A spread: the `level` quantile of `abs(log(ratio))` over the A/A cases. The default level is 0.9.\n * It refuses an A/A arm with no cases.\n */\nexport function aaSpread(aa: readonly PairedTime[], level = 0.9): number {\n const ratios = caseRatios(aa);\n if (ratios.length === 0) throw new RangeError(\"aaSpread: the A/A arm has no cases.\");\n return spreadOf(ratios, level);\n}\n\nfunction spreadOf(ratios: readonly CaseRatio[], level: number): number {\n return quantile(ratios.map((r) => Math.abs(Math.log(r.ratio))), level);\n}\n\n/** The options of a pooled band: the A/A records of earlier quiet runs, and a floor. The caller keeps the pool. */\nexport interface PoolOptions {\n /** The A/A records of the earlier runs. Give each run its own case names, for example with the run id as a prefix. */\n readonly records: readonly PairedTime[];\n /** The smallest noise of the band, on a log scale. The default is 0. A floor of `Math.log(1.05)` gives at least the band `[1 / 1.05, 1.05]`. */\n readonly floor?: number;\n /** The fewest pooled cases that give a spread. With fewer cases, the noise of the band is the floor. The default is 5. */\n readonly minimum?: number;\n /**\n * The run of a record, for example the id of its CI run. The verdict counts the runs of the pool with it.\n * The cases of one run share one runner, so they are not independent. Many cases from few runs show the noise of few runners.\n */\n readonly run?: (record: PairedTime) => string;\n}\n\n/** The facts of the pooled band of a verdict. */\nexport interface PoolFacts {\n /** The count of the pooled A/A cases. */\n readonly cases: number;\n /** The count of the runs of the pool, from the option `run`. It is undefined without that option. */\n readonly runs: number | undefined;\n /** The A/A spread of the pooled cases, or undefined when the pool has fewer cases than `minimum`. */\n readonly spread: number | undefined;\n readonly floor: number;\n /** This value is `true` when the spread of the pool is larger than the floor, so the spread gives the noise of the band. */\n readonly pooled: boolean;\n}\n\n/**\n * This function gives the pooled band of the kind `case`. Its noise is the larger of the floor and the A/A spread of the pooled records.\n * The spread is the `level` quantile of `abs(log(ratio))`, with the default level 0.9.\n *\n * A band with fewer pooled cases than `minimum` uses the floor alone. A band with no pooled cases has the median 1.\n */\nexport function pooledBand(pool: PoolOptions, level = 0.9): Band {\n return poolOf(pool, level).band;\n}\n\nfunction poolOf(pool: PoolOptions, level: number): { band: Band; facts: PoolFacts } {\n const floor = pool.floor ?? 0;\n const minimum = pool.minimum ?? 5;\n if (!(floor >= 0 && Number.isFinite(floor))) throw new RangeError(`pooledBand: the floor is a finite number of 0 or more, not ${floor}.`);\n if (!Number.isSafeInteger(minimum) || minimum < 1) throw new RangeError(`pooledBand: the minimum is a whole number of 1 or more, not ${minimum}.`);\n const ratios = caseRatios(pool.records);\n const spread = ratios.length >= minimum ? spreadOf(ratios, level) : undefined;\n const noise = Math.max(floor, spread ?? 0);\n const median = ratios.length === 0 ? 1 : Math.exp(quantile(ratios.map((r) => Math.log(r.ratio)), 0.5));\n const band: Band = { cases: ratios.length, kind: \"case\", noise, low: Math.exp(-noise), high: Math.exp(noise), median };\n const runs = pool.run === undefined ? undefined : new Set(pool.records.map(pool.run)).size;\n return { band, facts: { cases: ratios.length, runs, spread, floor, pooled: spread !== undefined && spread > floor } };\n}\n\n/** The four outcomes of a time verdict. The candidate is the arm `b`, so `faster` is a ratio below 1. */\nexport type TimeOutcome = \"faster\" | \"slower\" | \"same\" | \"cannot decide\";\n\n/** The options of a time verdict. The bootstrap gives the interval of the median ratio of the candidate, and the band `median`. */\n/**\n * The two rules of a time verdict.\n * - The rule `band` compares the interval of the median ratio of the candidate with the A/A band.\n * - The rule `difference` compares the interval of the candidate median over the A/A median with 1 and with `margin`.\n */\nexport type VerdictRule = \"band\" | \"difference\";\n\n/** The options of a time verdict. The bootstrap gives each interval of the verdict. */\nexport interface VerdictOptions extends BandOptions {\n /** The rule of the verdict. The default is `difference`, from the power test of `verdictPower`. */\n readonly rule?: VerdictRule;\n /**\n * The half width on a log scale of the ratios that the rule `difference` calls `same`. The default is 0.05.\n * An interval in the margin is `same`, also when it is wholly below 1.\n */\n readonly margin?: number;\n /**\n * The noise cap on the A/A spread of the run, on a log scale. Above the cap, the outcome is `cannot decide`.\n * The cap also limits the bias of the A/A arm: an A/A median ratio out of `[exp(-noiseCap), exp(noiseCap)]` gives `cannot decide`.\n * The default is no cap.\n */\n readonly noiseCap?: number;\n /** The quantile of the A/A spread of the noise cap and of the pooled band. The default is 0.9. */\n readonly spreadLevel?: number;\n /**\n * The pooled band. It replaces the band of the A/A arm of the run in the rule `band` and in `comparison`.\n * The rule `difference` uses the larger of `margin` and the noise of the pooled band as its margin. The default is no pool.\n */\n readonly pool?: PoolOptions;\n}\n\n/** The noise cap of a verdict: the A/A spread of the run, the A/A median ratio of the run and the cap. */\nexport interface NoiseCheck {\n /** The A/A spread of the run, or undefined when the A/A arm has no cases. */\n readonly spread: number | undefined;\n readonly cap: number;\n /** This value is `true` when the spread is above the cap, or when the A/A arm has no cases. */\n readonly noisy: boolean;\n /** The median ratio of the A/A cases of the run, or undefined when the A/A arm has no cases. A value far from 1 shows a bias of the order or of the arm slots. */\n readonly aaMedian: number | undefined;\n /**\n * This value is `true` when the A/A median ratio of the run is out of `[exp(-cap), exp(cap)]`.\n * With a spread level of 0.5 or more, a biased run is also noisy. The check decides alone only below that level.\n */\n readonly biased: boolean;\n}\n\n/** A time verdict, with the facts that it uses. */\nexport interface TimeVerdict {\n readonly outcome: TimeOutcome;\n /** The reason of the outcome, in one sentence. */\n readonly reason: string;\n readonly cases: readonly CaseRatio[];\n readonly rule: VerdictRule;\n /**\n * The interval that the rule compares, or undefined when there are no candidate cases.\n * With too few A/A cases, it is the interval of the median ratio of the candidate.\n * For the rule `band`, it is the bootstrap interval of the median ratio of the candidate.\n * For the rule `difference`, it is the interval of the candidate median ratio over the A/A median ratio.\n */\n readonly interval: Interval | undefined;\n /** The band of the A/A arm, or undefined when the A/A arm has too few cases. */\n readonly band: Band | undefined;\n /**\n * The counts of the cases out of the band, or undefined without a band.\n * The comparison uses the value `1 + log(ratio)` of each case and the noise of the band, so its two sides are the ends of the band.\n */\n readonly comparison: Comparison | undefined;\n /** The facts of the pooled band. The verdict has this field only with the option `pool`. */\n readonly pool?: PoolFacts;\n /** The noise cap. The verdict has this field only with the option `noiseCap`. */\n readonly noise?: NoiseCheck;\n}\n\n/**\n * This function gives the time verdict of the candidate arm `b` against the baseline arm `a`.\n * - The rule `difference` gives `same` when the interval is in `[exp(-margin), exp(margin)]`. This test comes first, so\n * an interval in the margin and below 1 is `same`, not `faster`.\n * - Out of the margin, the rule `difference` gives `faster` when the whole interval is below 1, and `slower` when it is above 1.\n * With the margin 0, each outcome stays the same as in 0.1.2.\n * - The rule `band` gives `faster` below the band, `slower` above the band, and `same` in the band.\n * - Each other case is `cannot decide`, and so is an A/A arm with too few cases.\n * - With `noiseCap`, an A/A spread of the run above the cap gives `cannot decide`.\n * - With `noiseCap`, an A/A median ratio of the run out of `[exp(-noiseCap), exp(noiseCap)]` also gives `cannot decide`.\n * - With `pool`, the pooled band replaces the band of the A/A arm of the run. The run still needs `minimum` A/A cases.\n */\nexport function timeVerdict(candidate: readonly PairedTime[], aa: readonly PairedTime[], options: VerdictOptions = {}): TimeVerdict {\n const level = options.spreadLevel ?? 0.9;\n if (options.noiseCap !== undefined && !(options.noiseCap >= 0 && Number.isFinite(options.noiseCap))) {\n throw new RangeError(`timeVerdict: the noise cap is a finite number of 0 or more, not ${options.noiseCap}.`);\n }\n const pool = poolFor(options);\n let verdict = ruleVerdict(candidate, aa, options, pool?.band);\n if (pool !== undefined) verdict = { ...verdict, pool: pool.facts };\n if (options.noiseCap !== undefined) {\n const cap = options.noiseCap;\n const aaRatios = caseRatios(aa);\n const spread = aaRatios.length === 0 ? undefined : spreadOf(aaRatios, level);\n const aaMedian = aaRatios.length === 0 ? undefined : Math.exp(quantile(aaRatios.map((r) => Math.log(r.ratio)), 0.5));\n const biased = aaMedian !== undefined && Math.abs(Math.log(aaMedian)) > cap;\n const noise: NoiseCheck = { spread, cap, noisy: spread === undefined || spread > cap, aaMedian, biased };\n verdict = { ...verdict, noise };\n // The early outcomes (no candidate cases, too few A/A cases) keep their reason. Each other outcome gives way to the cap.\n if (noise.noisy && verdict.band !== undefined) {\n const why = spread === undefined ? \"The A/A arm of the run has no cases, so the noise cap has no spread.\" : `The A/A spread of the run is ${round(spread)}, above the noise cap ${cap}.`;\n const reason = `${why} Without the cap, the outcome is \"${verdict.outcome}\".`;\n verdict = { ...verdict, outcome: \"cannot decide\", reason };\n } else if (noise.biased && verdict.band !== undefined) {\n const reason = `The A/A median ratio of the run is ${round(aaMedian!)}, out of [${round(Math.exp(-cap))}, ${round(Math.exp(cap))}] of the noise cap ${cap}. Without the cap, the outcome is \"${verdict.outcome}\".`;\n verdict = { ...verdict, outcome: \"cannot decide\", reason };\n }\n }\n return verdict;\n}\n\n/** This function gives the pooled band and its facts of the options, or undefined without the option `pool`. */\nfunction poolFor(options: VerdictOptions): { band: Band; facts: PoolFacts } | undefined {\n return options.pool === undefined ? undefined : poolOf(options.pool, options.spreadLevel ?? 0.9);\n}\n\n/** This function gives the margin of the rule `difference`: the larger of `margin` and the noise of the pooled band. It refuses a margin below 0. */\nfunction marginOf(options: VerdictOptions, pooled: Band | undefined): number {\n const given = options.margin ?? 0.05;\n if (!(given >= 0)) throw new RangeError(`timeVerdict: the margin is 0 or more, not ${given}.`);\n return pooled === undefined ? given : Math.max(given, pooled.noise);\n}\n\n/**\n * This function gives the margin that the rule `difference` of `timeVerdict` uses with these options. It uses the same code as the verdict.\n * The pooled band comes from the records of the option `pool`, not from the records of the run.\n */\nexport function verdictMargin(options: VerdictOptions = {}): number {\n return marginOf(options, poolFor(options)?.band);\n}\n\n/** This function gives the outcome of the rule. A pooled band replaces the band of the A/A arm, and it widens the margin of the rule `difference`. */\nfunction ruleVerdict(candidate: readonly PairedTime[], aa: readonly PairedTime[], options: VerdictOptions, pooled: Band | undefined): TimeVerdict {\n const rule = options.rule ?? \"difference\";\n const cases = caseRatios(candidate);\n const aaRatios = caseRatios(aa);\n const minimum = options.minimum ?? 5;\n const none = { cases, rule, interval: undefined, band: undefined, comparison: undefined };\n if (cases.length === 0) return { ...none, outcome: \"cannot decide\", reason: \"The candidate has no cases.\" };\n if (aaRatios.length < minimum) {\n const interval = bootstrapMedian(cases.map((c) => c.ratio), options.bootstrap);\n return { ...none, interval, outcome: \"cannot decide\", reason: `The A/A arm has ${aaRatios.length} cases, and a band needs ${minimum} or more.` };\n }\n const band = pooled ?? aaBand(aa, options);\n const comparison = compareRatios(cases.map((c) => 1 + Math.log(c.ratio)), { better: \"lower\", noise: band.noise });\n const facts = { cases, rule, band, comparison };\n if (rule === \"difference\") {\n const margin = marginOf(options, pooled);\n const shown = pooled === undefined ? margin : round(margin);\n const logs = cases.map((c) => Math.log(c.ratio));\n const aaLogs = aaRatios.map((c) => Math.log(c.ratio));\n const d = bootstrapTwo(logs, aaLogs, (x, y) => median(x) - median(y), options.bootstrap);\n const interval: Interval = { ...d, estimate: Math.exp(d.estimate), low: Math.exp(d.low), high: Math.exp(d.high) };\n const span = `The interval of the candidate median over the A/A median is [${round(interval.low)}, ${round(interval.high)}].`;\n // The margin comes first: an interval in the margin is `same`, also when it is wholly below or above 1.\n if (d.low >= -margin && d.high <= margin) return { ...facts, interval, outcome: \"same\", reason: `${span} The interval is in the margin of ${shown}.` };\n if (interval.high < 1) return { ...facts, interval, outcome: \"faster\", reason: `${span} The interval is below 1.` };\n if (interval.low > 1) return { ...facts, interval, outcome: \"slower\", reason: `${span} The interval is above 1.` };\n return { ...facts, interval, outcome: \"cannot decide\", reason: `${span} The interval holds 1 and crosses the margin of ${shown}.` };\n }\n const interval = bootstrapMedian(cases.map((c) => c.ratio), options.bootstrap);\n const span = `The interval of the median ratio is [${round(interval.low)}, ${round(interval.high)}], and the A/A band is [${round(band.low)}, ${round(band.high)}].`;\n if (interval.high < band.low) return { ...facts, interval, outcome: \"faster\", reason: `${span} The interval is below the band.` };\n if (interval.low > band.high) return { ...facts, interval, outcome: \"slower\", reason: `${span} The interval is above the band.` };\n if (interval.low >= band.low && interval.high <= band.high) return { ...facts, interval, outcome: \"same\", reason: `${span} The interval is in the band.` };\n return { ...facts, interval, outcome: \"cannot decide\", reason: `${span} The interval crosses an end of the band.` };\n}\n\nfunction round(x: number): number {\n return Math.round(x * 10_000) / 10_000;\n}\n","/**\n * The limit verdict of a bench: is the ratio of each case at most a limit? For example, the claim \"the new code takes at most\n * 2 times the time of the old code\" needs it. The time verdict compares only with 1.\n */\nimport { medianInterval } from \"@mark1russell7/rigor-statistics\";\nimport { type CaseRatio, type PairedTime, caseRatios } from \"./paired.ts\";\nimport { type Band, type BandOptions, aaBand } from \"./verdict.ts\";\n\n/** The ratio of one case with the interval of its median over the rounds. */\nexport interface CaseInterval extends CaseRatio {\n /** The ends of the interval: `exp` of `medianInterval` over the values `log(b / a)` of the rounds. */\n readonly low: number;\n readonly high: number;\n /** The coverage of the interval. It is at least the level. */\n readonly coverage: number;\n}\n\n/**\n * This function gives the ratio of each case with a distribution-free interval of its median, in the order of\n * `caseRatios`. It needs enough rounds for the level: 6 rounds or more for the level 0.95.\n */\nexport function caseIntervals(records: readonly PairedTime[], level = 0.95): CaseInterval[] {\n const logs = new Map<string, number[]>();\n for (const r of records) {\n const list = logs.get(r.case) ?? [];\n list.push(Math.log(r.b / r.a));\n logs.set(r.case, list);\n }\n return caseRatios(records).map((c) => {\n const interval = medianInterval(logs.get(c.case)!, level);\n return { ...c, low: Math.exp(interval.low), high: Math.exp(interval.high), coverage: interval.coverage };\n });\n}\n\n/** The three outcomes of a limit verdict. */\nexport type LimitOutcome = \"within\" | \"beyond\" | \"cannot decide\";\n\n/** The options of a limit verdict. */\nexport interface LimitOptions extends BandOptions {\n /** The largest ratio `b / a` that the claim permits, for example 2. */\n readonly limit: number;\n /** The level of the interval of each case. The default is 0.95. */\n readonly caseLevel?: number;\n}\n\n/** The verdict of one case against the limit. */\nexport interface CaseLimit extends CaseInterval {\n /** The high end of the interval of the case, times the high end of the A/A band. */\n readonly bound: number;\n /** The low end of the interval of the case, times the low end of the A/A band. */\n readonly floor: number;\n readonly outcome: LimitOutcome;\n}\n\n/** A limit verdict, with the facts that it uses. */\nexport interface LimitVerdict {\n readonly outcome: LimitOutcome;\n /** The reason of the outcome, in one sentence. */\n readonly reason: string;\n readonly limit: number;\n readonly cases: readonly CaseLimit[];\n /** The band of the A/A arm, or undefined when the A/A arm has too few cases. */\n readonly band: Band | undefined;\n}\n\n/**\n * This function gives the verdict of the claim \"the ratio `b / a` of each case is at most `limit`\". The A/A band widens\n * the interval of each case: the bound is the high end times the high end of the band.\n * - A case is `within` when its bound is at most the limit, and `beyond` when its floor is above the limit.\n * - The verdict is `beyond` when a case is `beyond`, and `within` when each case is `within`.\n * - Each other verdict is `cannot decide`, and so is an A/A arm with too few cases or a candidate with no cases.\n */\nexport function limitVerdict(candidate: readonly PairedTime[], aa: readonly PairedTime[], options: LimitOptions): LimitVerdict {\n const { limit } = options;\n if (!(limit > 0 && Number.isFinite(limit))) throw new RangeError(`limitVerdict: the limit is a finite number above 0, not ${limit}.`);\n const intervals = caseIntervals(candidate, options.caseLevel);\n const minimum = options.minimum ?? 5;\n if (intervals.length === 0) return { outcome: \"cannot decide\", reason: \"The candidate has no cases.\", limit, cases: [], band: undefined };\n const aaCount = caseRatios(aa).length;\n if (aaCount < minimum) {\n const cases = intervals.map((c) => ({ ...c, bound: c.high, floor: c.low, outcome: \"cannot decide\" as const }));\n return { outcome: \"cannot decide\", reason: `The A/A arm has ${aaCount} cases, and a band needs ${minimum} or more.`, limit, cases, band: undefined };\n }\n const band = aaBand(aa, options);\n const cases = intervals.map((c): CaseLimit => {\n const bound = c.high * band.high;\n const floor = c.low * band.low;\n const outcome: LimitOutcome = bound <= limit ? \"within\" : floor > limit ? \"beyond\" : \"cannot decide\";\n return { ...c, bound, floor, outcome };\n });\n const top = cases.reduce((a, b) => (b.bound > a.bound ? b : a));\n const beyond = cases.filter((c) => c.outcome === \"beyond\");\n if (beyond.length > 0) {\n return { outcome: \"beyond\", reason: `${beyond.length} of ${cases.length} cases are above the limit ${limit}, the first is ${JSON.stringify(beyond[0]!.case)}.`, limit, cases, band };\n }\n if (cases.every((c) => c.outcome === \"within\")) {\n return { outcome: \"within\", reason: `The largest bound is ${round(top.bound)} in the case ${JSON.stringify(top.case)}, and it is at most the limit ${limit}.`, limit, cases, band };\n }\n return { outcome: \"cannot decide\", reason: `The bound of the case ${JSON.stringify(top.case)} is ${round(top.bound)}, above the limit ${limit}, and its floor is not above it.`, limit, cases, band };\n}\n\nfunction round(x: number): number {\n return Math.round(x * 10_000) / 10_000;\n}\n","/**\n * The power test of a time verdict. It draws seeded benches with a known speedup and counts the verdicts that find it.\n * It also draws benches with equal arms and counts the false verdicts.\n */\nimport { random } from \"@mark1russell7/rigor-generators\";\nimport { firstArm, type PairedTime } from \"./paired.ts\";\nimport { type TimeOutcome, type VerdictOptions, timeVerdict, verdictMargin } from \"./verdict.ts\";\n\n/** The options of a power test. */\nexport interface PowerOptions {\n /** The count of the cases of the candidate and of the A/A arm. */\n readonly cases: number;\n /** The count of the rounds of each case. The default is 5. */\n readonly rounds?: number;\n /** The true ratio of the candidate time to the baseline time, for example 0.93 for a speedup of 7%. */\n readonly ratio: number;\n /** The standard deviation of the log time of one arm in one round. The default is 0.1. */\n readonly sigma?: number;\n /** The count of the seeded benches. The default is 200. */\n readonly trials?: number;\n /** The seed of the draws. The default is 1. */\n readonly seed?: number | string;\n /** The options of the verdict of each bench. */\n readonly verdict?: VerdictOptions;\n}\n\n/** The result of a power test: the share of each outcome over the trials. */\nexport interface Power {\n readonly trials: number;\n readonly outcomes: Readonly<Record<TimeOutcome, number>>;\n /**\n * The share of the trials whose outcome is the true one. For the rule `difference`, a ratio in the margin of the verdict has the true outcome `same`.\n * That margin is the larger of `margin` and the noise of the pooled band. The pool is the same in each trial, so each trial has the same margin.\n * Out of that margin, and for the rule `band`, the true outcome is `faster` below 1, `slower` above 1 and `same` at 1.\n */\n readonly power: number;\n}\n\n/**\n * This function draws `trials` benches and gives the share of each verdict. Each case has its own log scale.\n * Each arm of each round adds a normal noise of `sigma` to the log time.\n */\nexport function verdictPower(options: PowerOptions): Power {\n const rounds = options.rounds ?? 5;\n const sigma = options.sigma ?? 0.1;\n const trials = options.trials ?? 200;\n if (!Number.isSafeInteger(options.cases) || options.cases < 1) throw new RangeError(`verdictPower: cases is a whole number of 1 or more, not ${options.cases}.`);\n if (!(options.ratio > 0 && Number.isFinite(options.ratio))) throw new RangeError(`verdictPower: the ratio is a finite number above 0, not ${options.ratio}.`);\n const r = random(options.seed ?? 1);\n const bench = (ratio: number, prefix: string): PairedTime[] => {\n const out: PairedTime[] = [];\n for (let c = 0; c < options.cases; c++) {\n const scale = 10 * Math.exp(r.normal());\n for (let round = 0; round < rounds; round++) {\n const a = scale * Math.exp(r.normal(0, sigma));\n const b = scale * ratio * Math.exp(r.normal(0, sigma));\n out.push({ case: `${prefix}${c}`, round, first: firstArm(round, c), a, b });\n }\n }\n return out;\n };\n const truth = trueOutcome(options.ratio, options.verdict);\n const counts: Record<TimeOutcome, number> = { faster: 0, slower: 0, same: 0, \"cannot decide\": 0 };\n for (let t = 0; t < trials; t++) {\n const aa = bench(1, \"aa\");\n const candidate = bench(options.ratio, \"c\");\n counts[timeVerdict(candidate, aa, options.verdict).outcome]++;\n }\n const outcomes = Object.fromEntries(Object.entries(counts).map(([k, n]) => [k, n / trials])) as Record<TimeOutcome, number>;\n return { trials, outcomes, power: outcomes[truth] };\n}\n\n/** This function gives the true outcome of a ratio. The margin of the rule `difference` comes first, as in `timeVerdict`. */\nfunction trueOutcome(ratio: number, verdict: VerdictOptions = {}): TimeOutcome {\n if ((verdict.rule ?? \"difference\") === \"difference\" && Math.abs(Math.log(ratio)) <= verdictMargin(verdict)) return \"same\";\n return ratio < 1 ? \"faster\" : ratio > 1 ? \"slower\" : \"same\";\n}\n","/**\n * The timed rounds of one case in one process. The two arms first run for a warm-up time. Then the count of calls of\n * one batch grows until a batch of arm `a` takes the target time. Each round times one batch of each arm, in the order\n * of `firstArm`. Start this function in a fresh process for each case.\n */\nimport { performance } from \"node:perf_hooks\";\nimport { type Arm, type PairedTime, firstArm } from \"./paired.ts\";\n\n/** The options of the timed rounds of one case. */\nexport interface RoundsOptions {\n /** The name of the case. */\n readonly case: string;\n /** The count of the rounds. */\n readonly rounds: number;\n /** The offset of `firstArm`: give the index of the case, so half of the cases start with each arm. The default is 0. */\n readonly offset?: number;\n /** The least time in milliseconds of one batch of arm `a`. The default is 10. */\n readonly targetMs?: number;\n /** The time in milliseconds of the warm-up of the two arms. The default is 1000. */\n readonly warmMs?: number;\n /** The clock in milliseconds. The default is `performance.now`. */\n readonly now?: () => number;\n}\n\n/** The result of the timed rounds of one case. */\nexport interface Rounds {\n readonly records: PairedTime[];\n /** The count of calls of each arm in one batch. */\n readonly count: number;\n /** The sum of the numbers that the arms gave. The engine cannot remove the work of a call, because this sum uses it. */\n readonly sink: number;\n}\n\n/**\n * This function times the arms `a` and `b` of one case, and gives one `PairedTime` record for each round. The time of\n * a record is the time of one batch, in milliseconds. Each call of an arm gives a number, and the sum of these numbers\n * keeps the work.\n */\nexport function timeRounds(arms: Readonly<Record<Arm, () => number>>, options: RoundsOptions): Rounds {\n const { rounds } = options;\n const offset = options.offset ?? 0;\n const targetMs = options.targetMs ?? 10;\n const warmMs = options.warmMs ?? 1000;\n const now = options.now ?? (() => performance.now());\n if (!Number.isSafeInteger(rounds) || rounds < 1) throw new RangeError(`timeRounds: the rounds are a whole number of 1 or more, not ${rounds}.`);\n if (!Number.isSafeInteger(offset)) throw new RangeError(`timeRounds: the offset is a whole number, not ${offset}.`);\n if (!(targetMs > 0) || !(warmMs >= 0)) throw new RangeError(\"timeRounds: the target time is above 0, and the warm-up time is 0 or more.\");\n let sink = 0;\n const batch = (arm: Arm, count: number): number => {\n const run = arms[arm];\n const start = now();\n for (let i = 0; i < count; i++) sink += run();\n return now() - start;\n };\n let count = 1;\n const warmUntil = now() + warmMs;\n while (now() < warmUntil) {\n if (batch(\"a\", count) < targetMs / 4) count *= 2;\n batch(\"b\", count);\n }\n while (batch(\"a\", count) < targetMs) count *= 2;\n const records: PairedTime[] = [];\n for (let round = 0; round < rounds; round++) {\n const first = firstArm(round, offset);\n const second: Arm = first === \"a\" ? \"b\" : \"a\";\n const times = { [first]: batch(first, count), [second]: batch(second, count) } as Record<Arm, number>;\n records.push({ case: options.case, round, first, a: times.a, b: times.b });\n }\n return { records, count, sink };\n}\n"],"mappings":";;;;;;;;;;;;AA0BA,SAAgB,SAAS,OAAe,SAAS,GAAQ;CACvD,IAAI,CAAC,OAAO,cAAc,KAAK,KAAK,QAAQ,GAAG,MAAM,IAAI,WAAW,2DAA2D,MAAM,EAAE;CACvI,IAAI,CAAC,OAAO,cAAc,MAAM,GAAG,MAAM,IAAI,WAAW,+CAA+C,OAAO,EAAE;CAChH,SAAU,QAAQ,UAAU,IAAK,KAAK,MAAM,IAAI,MAAM;AACxD;;AAGA,SAAgB,gBAAgB,QAAgC;CAC9D,MAAM,QAAQ,0BAA0B,KAAK,UAAU,OAAO,IAAI,EAAE,UAAU,OAAO;CACrF,IAAI,OAAO,OAAO,SAAS,YAAY,OAAO,SAAS,IAAI,MAAM,IAAI,WAAW,0DAA0D;CAC1I,IAAI,CAAC,OAAO,cAAc,OAAO,KAAK,KAAK,OAAO,QAAQ,GAAG,MAAM,IAAI,WAAW,uBAAuB,MAAM,4CAA4C;CAC3J,IAAI,OAAO,UAAU,OAAO,OAAO,UAAU,KAAK,MAAM,IAAI,WAAW,uBAAuB,MAAM,qCAAqC,OAAO,OAAO,KAAK,EAAE,EAAE;CAChK,KAAK,MAAM,OAAO,CAAC,KAAK,GAAG,GAAY;EACrC,MAAM,KAAK,OAAO;EAClB,IAAI,EAAE,OAAO,OAAO,YAAY,OAAO,SAAS,EAAE,KAAK,KAAK,IAAI,MAAM,IAAI,WAAW,uBAAu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7E,QAAQ,KAAK;GAAE,MAAM,QAAQ;GAAM;GAAO;GAAO,GAAG,MAAM;GAAG,GAAG,MAAM;EAAE,CAAC;CAC3E;CACA,OAAO;EAAE;EAAS;EAAO;CAAK;AAChC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@mark1russell7/rigor-bench",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.2.0",
|
|
5
5
|
"description": "The paired-time records of a bench: the order that turns each round, the ratio of each case, and the time verdict against the band of an A/A arm.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"benchmark",
|
|
@@ -35,10 +35,10 @@
|
|
|
35
35
|
"node": ">=22"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
+
"@mark1russell7/rigor-generators": "^0.1.1",
|
|
38
39
|
"@mark1russell7/rigor-statistics": "^0.1.5"
|
|
39
40
|
},
|
|
40
41
|
"devDependencies": {
|
|
41
|
-
"@mark1russell7/rigor-generators": "^0.1.1",
|
|
42
42
|
"@mark1russell7/cue": "^1.0.2",
|
|
43
43
|
"@types/node": "^26.6.5",
|
|
44
44
|
"tsdown": "^0.23.1",
|