@mark1russell7/rigor-bench 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/README.md +98 -2
- package/build/index.d.ts +225 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +408 -0
- package/build/index.js.map +1 -0
- package/package.json +59 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Mark Russell
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,99 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @mark1russell7/rigor-bench
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The paired-time records of a bench, and the time verdict against an A/A arm. This package is the first part of the shared bench harness of rigor.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npm install @mark1russell7/rigor-bench
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## The method
|
|
10
|
+
|
|
11
|
+
- Each round runs the two arms of a pair on one case, one after the other. Arm `a` is the baseline, and arm `b` is the candidate.
|
|
12
|
+
- The order turns each round (`firstArm`). Thus a warm cache or a slow start does not always help the same arm.
|
|
13
|
+
- An A/A pair runs the same code in its two arms. Its ratios show how far apart two equal arms come on the machine.
|
|
14
|
+
- The ratio of a case is `b / a` over its rounds (`caseRatios`).
|
|
15
|
+
- The default rule `difference` gives the bootstrap interval of the candidate median over the A/A median. The verdict compares it with 1.
|
|
16
|
+
|
|
17
|
+
## Give a verdict
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { firstArm, timeVerdict, type PairedTime } from "@mark1russell7/rigor-bench";
|
|
21
|
+
|
|
22
|
+
const first = firstArm(round, caseIndex); // "a" or "b": run this arm first
|
|
23
|
+
const records: PairedTime[] = [{ case: "board-1", round: 0, first: "a", a: 12.1, b: 10.4 }];
|
|
24
|
+
const v = timeVerdict(records, aaRecords);
|
|
25
|
+
|
|
26
|
+
v.outcome; // "faster", "slower", "same" or "cannot decide"
|
|
27
|
+
v.reason; // one sentence with the interval and the band
|
|
28
|
+
v.comparison; // the cases that gain and drop beyond the band
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## The functions
|
|
32
|
+
|
|
33
|
+
| Function | What it gives |
|
|
34
|
+
| --- | --- |
|
|
35
|
+
| `firstArm(round, offset)` | The arm that runs first. The order turns each round, and an odd offset starts with arm `b`. |
|
|
36
|
+
| `checkPairedTime(record)` | The record, or a `RangeError` for a time that is not a finite number above 0. |
|
|
37
|
+
| `caseRatios(records)` | The ratio of each case. It refuses 2 records of one round, and an order that did not turn. |
|
|
38
|
+
| `aaBand(aa, options)` | The band of the A/A arm, symmetric on a log scale. The kind `median` (the default) holds the A/A median, and the kind `case` holds one A/A case. It needs 5 cases or more. |
|
|
39
|
+
| `timeVerdict(candidate, aa, options)` | The outcome of the rule `difference` (the default) or `band`. |
|
|
40
|
+
| `caseIntervals(records, level)` | The ratio of each case with a distribution-free interval of its median over the rounds. The level 0.95 needs 6 rounds or more. |
|
|
41
|
+
| `limitVerdict(candidate, aa, options)` | The verdict of the claim "the ratio of each case is at most `limit`": `within`, `beyond` or `cannot decide`. |
|
|
42
|
+
| `timeRounds(arms, options)` | The timed rounds of one case in one process: a warm-up, a batch of at least the target time, and the order of `firstArm`. |
|
|
43
|
+
| `verdictPower(options)` | The share of each outcome over seeded benches with a known ratio: the power test of a rule. |
|
|
44
|
+
|
|
45
|
+
## A claim with a limit
|
|
46
|
+
|
|
47
|
+
`timeVerdict` compares the ratio with 1. A claim with a limit needs `limitVerdict`. An example is "the new code takes at most 2 times the time of the old code":
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
const v = limitVerdict(records, aaRecords, { limit: 2 });
|
|
51
|
+
|
|
52
|
+
v.outcome; // "within", "beyond" or "cannot decide"
|
|
53
|
+
v.cases; // the interval, the bound and the outcome of each case
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
- The A/A band widens the interval of each case. The bound is the high end of the interval times the high end of the band.
|
|
57
|
+
- A case is `within` when its bound is at most the limit. It is `beyond` when its low end times the low end of the band is above the limit.
|
|
58
|
+
- The verdict is `beyond` when a case is `beyond`, and `within` when each case is `within`.
|
|
59
|
+
|
|
60
|
+
The verdict has no correction for many cases. Each case has its own interval at the level `caseLevel`. Thus with many cases, a verdict `beyond` can come from noise only. Set `caseLevel` higher when a bench has many cases. A correction of Holm is an option for a later version.
|
|
61
|
+
|
|
62
|
+
## Time the rounds
|
|
63
|
+
|
|
64
|
+
`timeRounds` times one case in one process. Start a fresh process for each case and each pair, and give the index of the case as `offset`:
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
const { records } = timeRounds({ a: () => oldCode(input), b: () => newCode(input) }, { case: "board-1", rounds: 31, offset: 0 });
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Each arm gives a number. The engine cannot remove the work of a call, because the sum of these numbers uses it.
|
|
71
|
+
|
|
72
|
+
## The outcomes
|
|
73
|
+
|
|
74
|
+
| Outcome | The rule `difference` (the default) | The rule `band` |
|
|
75
|
+
| --- | --- | --- |
|
|
76
|
+
| `faster` | The whole interval is below 1. | The interval of the median ratio is below the band. |
|
|
77
|
+
| `slower` | The whole interval is above 1. | The interval is above the band. |
|
|
78
|
+
| `same` | The interval is in `[exp(-margin), exp(margin)]`. The default margin is 0.05. | The interval is in the band. |
|
|
79
|
+
| `cannot decide` | The interval holds 1 and crosses the margin. | The interval crosses an end of the band. |
|
|
80
|
+
|
|
81
|
+
Both rules give `cannot decide` when the A/A arm has fewer than 5 cases, or when the candidate has no cases.
|
|
82
|
+
|
|
83
|
+
## The power test
|
|
84
|
+
|
|
85
|
+
`verdictPower` drew 200 seeded benches for each cell. Each case had 5 rounds. The log time of each arm in each round had a normal noise of 0.1. The bootstrap had 1000 runs.
|
|
86
|
+
|
|
87
|
+
| Rule | Cases | Finds a true speedup of 7% | Calls that speedup `same` | False `faster` or `slower` on equal arms |
|
|
88
|
+
| --- | --- | --- | --- | --- |
|
|
89
|
+
| `band`, kind `case` | 5 | 0.025 | 0.185 | 0 |
|
|
90
|
+
| `band`, kind `case` | 10 | 0 | 0.515 | 0 |
|
|
91
|
+
| `band`, kind `case` | 20 | 0 | 0.755 | 0 |
|
|
92
|
+
| `band`, kind `median` | 5 | 0.025 | 0.22 | 0 |
|
|
93
|
+
| `band`, kind `median` | 10 | 0.045 | 0.1 | 0 |
|
|
94
|
+
| `band`, kind `median` | 20 | 0.22 | 0.035 | 0 |
|
|
95
|
+
| `difference` | 5 | 0.235 | 0 | 0.04 |
|
|
96
|
+
| `difference` | 10 | 0.44 | 0 | 0.045 |
|
|
97
|
+
| `difference` | 20 | 0.71 | 0 | 0.04 |
|
|
98
|
+
|
|
99
|
+
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.
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { BootstrapOptions, Comparison, Interval } from "@mark1russell7/rigor-statistics";
|
|
2
|
+
/** The two arms of a pair. Arm `a` is the baseline, and arm `b` is the candidate. */
|
|
3
|
+
type Arm = "a" | "b";
|
|
4
|
+
/** One round of one pair on one case: the times of the two arms in milliseconds, and the arm that ran first. */
|
|
5
|
+
interface PairedTime {
|
|
6
|
+
/** The name of the case: one input of the bench. */
|
|
7
|
+
readonly case: string;
|
|
8
|
+
/** The number of the round, a whole number of 0 or more. */
|
|
9
|
+
readonly round: number;
|
|
10
|
+
readonly first: Arm;
|
|
11
|
+
/** The time of the baseline arm, in milliseconds. */
|
|
12
|
+
readonly a: number;
|
|
13
|
+
/** The time of the candidate arm, in milliseconds. */
|
|
14
|
+
readonly b: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* This function gives the arm that runs first in a round. The order turns each round. A case with an odd `offset`
|
|
18
|
+
* starts with arm `b`, so half of the cases start with each arm.
|
|
19
|
+
*/
|
|
20
|
+
export declare function firstArm(round: number, offset?: number): Arm;
|
|
21
|
+
/** This function examines one record. A time that is not a finite number above 0 is an error. */
|
|
22
|
+
export declare function checkPairedTime(record: PairedTime): PairedTime;
|
|
23
|
+
/** The ratio of one case: the candidate time over the baseline time, over the rounds of the case. */
|
|
24
|
+
interface CaseRatio {
|
|
25
|
+
readonly case: string;
|
|
26
|
+
/** The value `exp(median(log(b / a)))` over the rounds. For an odd count of rounds, it is the median of the ratios. */
|
|
27
|
+
readonly ratio: number;
|
|
28
|
+
readonly rounds: number;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* This function gives the ratio of each case, in the order of the first record of each case.
|
|
32
|
+
* It examines each record. It refuses a case with 2 records of one round.
|
|
33
|
+
* It also refuses a case whose two orders differ in count by more than 1, because that order did not turn each round.
|
|
34
|
+
*/
|
|
35
|
+
export declare function caseRatios(records: readonly PairedTime[]): CaseRatio[];
|
|
36
|
+
/**
|
|
37
|
+
* The two kinds of an A/A band.
|
|
38
|
+
* - The band `case` holds the ratio of one A/A case. It is wide, so it finds only a large change.
|
|
39
|
+
* - The band `median` holds the median ratio of the A/A cases. It has the scale of the median of the candidate.
|
|
40
|
+
*/
|
|
41
|
+
type BandKind = "case" | "median";
|
|
42
|
+
/** The options of the A/A band. */
|
|
43
|
+
interface BandOptions {
|
|
44
|
+
/** The kind of the band. The default is `median`, from the power test of `verdictPower`. */
|
|
45
|
+
readonly kind?: BandKind;
|
|
46
|
+
/** The quantile of the band `case`, or the level of the bootstrap of the band `median`. The default is 0.95. */
|
|
47
|
+
readonly level?: number;
|
|
48
|
+
/** The fewest A/A cases that give a band. The default is 5, the 5-seed rule. */
|
|
49
|
+
readonly minimum?: number;
|
|
50
|
+
/** The bootstrap of the band `median`. The level of the band replaces its level. */
|
|
51
|
+
readonly bootstrap?: BootstrapOptions;
|
|
52
|
+
}
|
|
53
|
+
/** The band of the A/A arm: two equal arms come out in this band of ratios. */
|
|
54
|
+
interface Band {
|
|
55
|
+
/** The count of the A/A cases. */
|
|
56
|
+
readonly cases: number;
|
|
57
|
+
readonly kind: BandKind;
|
|
58
|
+
/**
|
|
59
|
+
* The half width of the band on a log scale.
|
|
60
|
+
* For the band `case`, it is the `level` quantile of `abs(log(ratio))` over the A/A cases.
|
|
61
|
+
* For the band `median`, it is the larger distance of an end of the bootstrap interval of the A/A median from 0.
|
|
62
|
+
*/
|
|
63
|
+
readonly noise: number;
|
|
64
|
+
/** The ends of the band: `exp(-noise)` and `exp(noise)`. */
|
|
65
|
+
readonly low: number;
|
|
66
|
+
readonly high: number;
|
|
67
|
+
/** The median ratio of the A/A cases. A value far from 1 shows a bias of the order or of the arm slots. */
|
|
68
|
+
readonly median: number;
|
|
69
|
+
}
|
|
70
|
+
/** This function gives the band of the A/A arm. The band is symmetric on a log scale. It refuses fewer cases than `minimum`. */
|
|
71
|
+
export declare function aaBand(aa: readonly PairedTime[], options?: BandOptions): Band;
|
|
72
|
+
/** The four outcomes of a time verdict. The candidate is the arm `b`, so `faster` is a ratio below 1. */
|
|
73
|
+
type TimeOutcome = "faster" | "slower" | "same" | "cannot decide";
|
|
74
|
+
/** The options of a time verdict. The bootstrap gives the interval of the median ratio of the candidate, and the band `median`. */
|
|
75
|
+
/**
|
|
76
|
+
* The two rules of a time verdict.
|
|
77
|
+
* - The rule `band` compares the interval of the median ratio of the candidate with the A/A band.
|
|
78
|
+
* - The rule `difference` compares the interval of the candidate median over the A/A median with 1 and with `margin`.
|
|
79
|
+
*/
|
|
80
|
+
type VerdictRule = "band" | "difference";
|
|
81
|
+
/** The options of a time verdict. The bootstrap gives each interval of the verdict. */
|
|
82
|
+
interface VerdictOptions extends BandOptions {
|
|
83
|
+
/** The rule of the verdict. The default is `difference`, from the power test of `verdictPower`. */
|
|
84
|
+
readonly rule?: VerdictRule;
|
|
85
|
+
/** The half width on a log scale of the ratios that the rule `difference` calls `same`. The default is 0.05. */
|
|
86
|
+
readonly margin?: number;
|
|
87
|
+
}
|
|
88
|
+
/** A time verdict, with the facts that it uses. */
|
|
89
|
+
interface TimeVerdict {
|
|
90
|
+
readonly outcome: TimeOutcome;
|
|
91
|
+
/** The reason of the outcome, in one sentence. */
|
|
92
|
+
readonly reason: string;
|
|
93
|
+
readonly cases: readonly CaseRatio[];
|
|
94
|
+
readonly rule: VerdictRule;
|
|
95
|
+
/**
|
|
96
|
+
* The interval that the rule compares, or undefined when there are no candidate cases.
|
|
97
|
+
* With too few A/A cases, it is the interval of the median ratio of the candidate.
|
|
98
|
+
* For the rule `band`, it is the bootstrap interval of the median ratio of the candidate.
|
|
99
|
+
* For the rule `difference`, it is the interval of the candidate median ratio over the A/A median ratio.
|
|
100
|
+
*/
|
|
101
|
+
readonly interval: Interval | undefined;
|
|
102
|
+
/** The band of the A/A arm, or undefined when the A/A arm has too few cases. */
|
|
103
|
+
readonly band: Band | undefined;
|
|
104
|
+
/**
|
|
105
|
+
* The counts of the cases out of the band, or undefined without a band.
|
|
106
|
+
* 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.
|
|
107
|
+
*/
|
|
108
|
+
readonly comparison: Comparison | undefined;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* This function gives the time verdict of the candidate arm `b` against the baseline arm `a`.
|
|
112
|
+
* - The rule `difference` gives `faster` when the whole interval is below 1, and `slower` when it is above 1.
|
|
113
|
+
* It gives `same` when the interval is in `[exp(-margin), exp(margin)]`.
|
|
114
|
+
* - The rule `band` gives `faster` below the band, `slower` above the band, and `same` in the band.
|
|
115
|
+
* - Each other case is `cannot decide`, and so is an A/A arm with too few cases.
|
|
116
|
+
*/
|
|
117
|
+
export declare function timeVerdict(candidate: readonly PairedTime[], aa: readonly PairedTime[], options?: VerdictOptions): TimeVerdict;
|
|
118
|
+
/** The ratio of one case with the interval of its median over the rounds. */
|
|
119
|
+
interface CaseInterval extends CaseRatio {
|
|
120
|
+
/** The ends of the interval: `exp` of `medianInterval` over the values `log(b / a)` of the rounds. */
|
|
121
|
+
readonly low: number;
|
|
122
|
+
readonly high: number;
|
|
123
|
+
/** The coverage of the interval. It is at least the level. */
|
|
124
|
+
readonly coverage: number;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* This function gives the ratio of each case with a distribution-free interval of its median, in the order of
|
|
128
|
+
* `caseRatios`. It needs enough rounds for the level: 6 rounds or more for the level 0.95.
|
|
129
|
+
*/
|
|
130
|
+
export declare function caseIntervals(records: readonly PairedTime[], level?: number): CaseInterval[];
|
|
131
|
+
/** The three outcomes of a limit verdict. */
|
|
132
|
+
type LimitOutcome = "within" | "beyond" | "cannot decide";
|
|
133
|
+
/** The options of a limit verdict. */
|
|
134
|
+
interface LimitOptions extends BandOptions {
|
|
135
|
+
/** The largest ratio `b / a` that the claim permits, for example 2. */
|
|
136
|
+
readonly limit: number;
|
|
137
|
+
/** The level of the interval of each case. The default is 0.95. */
|
|
138
|
+
readonly caseLevel?: number;
|
|
139
|
+
}
|
|
140
|
+
/** The verdict of one case against the limit. */
|
|
141
|
+
interface CaseLimit extends CaseInterval {
|
|
142
|
+
/** The high end of the interval of the case, times the high end of the A/A band. */
|
|
143
|
+
readonly bound: number;
|
|
144
|
+
/** The low end of the interval of the case, times the low end of the A/A band. */
|
|
145
|
+
readonly floor: number;
|
|
146
|
+
readonly outcome: LimitOutcome;
|
|
147
|
+
}
|
|
148
|
+
/** A limit verdict, with the facts that it uses. */
|
|
149
|
+
interface LimitVerdict {
|
|
150
|
+
readonly outcome: LimitOutcome;
|
|
151
|
+
/** The reason of the outcome, in one sentence. */
|
|
152
|
+
readonly reason: string;
|
|
153
|
+
readonly limit: number;
|
|
154
|
+
readonly cases: readonly CaseLimit[];
|
|
155
|
+
/** The band of the A/A arm, or undefined when the A/A arm has too few cases. */
|
|
156
|
+
readonly band: Band | undefined;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* This function gives the verdict of the claim "the ratio `b / a` of each case is at most `limit`". The A/A band widens
|
|
160
|
+
* the interval of each case: the bound is the high end times the high end of the band.
|
|
161
|
+
* - A case is `within` when its bound is at most the limit, and `beyond` when its floor is above the limit.
|
|
162
|
+
* - The verdict is `beyond` when a case is `beyond`, and `within` when each case is `within`.
|
|
163
|
+
* - Each other verdict is `cannot decide`, and so is an A/A arm with too few cases or a candidate with no cases.
|
|
164
|
+
*/
|
|
165
|
+
export declare function limitVerdict(candidate: readonly PairedTime[], aa: readonly PairedTime[], options: LimitOptions): LimitVerdict;
|
|
166
|
+
/** The options of a power test. */
|
|
167
|
+
interface PowerOptions {
|
|
168
|
+
/** The count of the cases of the candidate and of the A/A arm. */
|
|
169
|
+
readonly cases: number;
|
|
170
|
+
/** The count of the rounds of each case. The default is 5. */
|
|
171
|
+
readonly rounds?: number;
|
|
172
|
+
/** The true ratio of the candidate time to the baseline time, for example 0.93 for a speedup of 7%. */
|
|
173
|
+
readonly ratio: number;
|
|
174
|
+
/** The standard deviation of the log time of one arm in one round. The default is 0.1. */
|
|
175
|
+
readonly sigma?: number;
|
|
176
|
+
/** The count of the seeded benches. The default is 200. */
|
|
177
|
+
readonly trials?: number;
|
|
178
|
+
/** The seed of the draws. The default is 1. */
|
|
179
|
+
readonly seed?: number | string;
|
|
180
|
+
/** The options of the verdict of each bench. */
|
|
181
|
+
readonly verdict?: VerdictOptions;
|
|
182
|
+
}
|
|
183
|
+
/** The result of a power test: the share of each outcome over the trials. */
|
|
184
|
+
interface Power {
|
|
185
|
+
readonly trials: number;
|
|
186
|
+
readonly outcomes: Readonly<Record<TimeOutcome, number>>;
|
|
187
|
+
/** The share of the trials whose outcome is the true one: `faster` for a ratio below 1, `slower` above 1, `same` at 1. */
|
|
188
|
+
readonly power: number;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* This function draws `trials` benches and gives the share of each verdict. Each case has its own log scale.
|
|
192
|
+
* Each arm of each round adds a normal noise of `sigma` to the log time.
|
|
193
|
+
*/
|
|
194
|
+
export declare function verdictPower(options: PowerOptions): Power;
|
|
195
|
+
/** The options of the timed rounds of one case. */
|
|
196
|
+
interface RoundsOptions {
|
|
197
|
+
/** The name of the case. */
|
|
198
|
+
readonly case: string;
|
|
199
|
+
/** The count of the rounds. */
|
|
200
|
+
readonly rounds: number;
|
|
201
|
+
/** The offset of `firstArm`: give the index of the case, so half of the cases start with each arm. The default is 0. */
|
|
202
|
+
readonly offset?: number;
|
|
203
|
+
/** The least time in milliseconds of one batch of arm `a`. The default is 10. */
|
|
204
|
+
readonly targetMs?: number;
|
|
205
|
+
/** The time in milliseconds of the warm-up of the two arms. The default is 1000. */
|
|
206
|
+
readonly warmMs?: number;
|
|
207
|
+
/** The clock in milliseconds. The default is `performance.now`. */
|
|
208
|
+
readonly now?: () => number;
|
|
209
|
+
}
|
|
210
|
+
/** The result of the timed rounds of one case. */
|
|
211
|
+
interface Rounds {
|
|
212
|
+
readonly records: PairedTime[];
|
|
213
|
+
/** The count of calls of each arm in one batch. */
|
|
214
|
+
readonly count: number;
|
|
215
|
+
/** The sum of the numbers that the arms gave. The engine cannot remove the work of a call, because this sum uses it. */
|
|
216
|
+
readonly sink: number;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* This function times the arms `a` and `b` of one case, and gives one `PairedTime` record for each round. The time of
|
|
220
|
+
* a record is the time of one batch, in milliseconds. Each call of an arm gives a number, and the sum of these numbers
|
|
221
|
+
* keeps the work.
|
|
222
|
+
*/
|
|
223
|
+
export declare function timeRounds(arms: Readonly<Record<Arm, () => number>>, options: RoundsOptions): Rounds;
|
|
224
|
+
export type { Arm, Band, BandKind, BandOptions, CaseInterval, CaseLimit, CaseRatio, LimitOptions, LimitOutcome, LimitVerdict, PairedTime, Power, PowerOptions, Rounds, RoundsOptions, TimeOutcome, TimeVerdict, VerdictOptions, VerdictRule };
|
|
225
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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;;UAGK;;WAEN;;WAEA;WACA,OAAO;;WAEP;;WAEA;;;;;;wBAOK,SAAS,eAAe,kBAAa;;wBAOrC,gBAAgB,QAAQ,aAAa;;UAapC;WACN;;WAEA;WACA;;;;;;;wBAQK,WAAW,kBAAkB,eAAe;;;;;;KC7ChD;;UAGK;;WAEN,OAAO;;WAEP;;WAEA;;WAEA,YAAY;;;UAIN;;WAEN;WACA,MAAM;;;;;;WAMN;;WAEA;WACA;;WAEA;;;wBAIK,OAAO,aAAa,cAAc,UAAS,cAAmB;;KAiBlE;;;;;;;KAQA;;UAGK,uBAAuB;;WAE7B,OAAO;;WAEP;;;UAIM;WACN,SAAS;;WAET;WACA,gBAAgB;WAChB,MAAM;;;;;;;WAON,UAAU;;WAEV,MAAM;;;;;WAKN,YAAY;;;;;;;;;wBAUP,YAAY,oBAAoB,cAAc,aAAa,cAAc,UAAS,iBAAsB;;UCtGvG,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;;WAE1B;;;;;;wBAOK,aAAa,SAAS,eAAe;;UC7BpC;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;;UAIM;WACN,SAAS;;WAET;;WAEA;;;;;;;wBAQK,WAAW,MAAM,SAAS,OAAO,qBAAqB,SAAS,gBAAgB"}
|
package/build/index.js
ADDED
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
import { bootstrapMedian, bootstrapTwo, compareRatios, median, medianInterval, quantile } from "@mark1russell7/rigor-statistics";
|
|
2
|
+
import { random } from "@mark1russell7/rigor-generators";
|
|
3
|
+
import { performance } from "node:perf_hooks";
|
|
4
|
+
// src/paired.ts
|
|
5
|
+
/**
|
|
6
|
+
* 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
|
|
7
|
+
* fresh process. The order turns each round, so a warm cache or a slow start does not always help the same arm.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* This function gives the arm that runs first in a round. The order turns each round. A case with an odd `offset`
|
|
11
|
+
* starts with arm `b`, so half of the cases start with each arm.
|
|
12
|
+
*/
|
|
13
|
+
function firstArm(round, offset = 0) {
|
|
14
|
+
if (!Number.isSafeInteger(round) || round < 0) throw new RangeError(`firstArm: the round is a whole number of 0 or more, not ${round}.`);
|
|
15
|
+
if (!Number.isSafeInteger(offset)) throw new RangeError(`firstArm: the offset is a whole number, not ${offset}.`);
|
|
16
|
+
return ((round + offset) % 2 + 2) % 2 === 0 ? "a" : "b";
|
|
17
|
+
}
|
|
18
|
+
/** This function examines one record. A time that is not a finite number above 0 is an error. */
|
|
19
|
+
function checkPairedTime(record) {
|
|
20
|
+
const where = `the record of the case ${JSON.stringify(record.case)}, round ${record.round}`;
|
|
21
|
+
if (typeof record.case !== "string" || record.case === "") throw new RangeError("checkPairedTime: the case is a string that is not empty.");
|
|
22
|
+
if (!Number.isSafeInteger(record.round) || record.round < 0) throw new RangeError(`checkPairedTime: in ${where}, the round is a whole number of 0 or more.`);
|
|
23
|
+
if (record.first !== "a" && record.first !== "b") throw new RangeError(`checkPairedTime: in ${where}, the first arm is "a" or "b", not ${String(record.first)}.`);
|
|
24
|
+
for (const arm of ["a", "b"]) {
|
|
25
|
+
const ms = record[arm];
|
|
26
|
+
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)}.`);
|
|
27
|
+
}
|
|
28
|
+
return record;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* This function gives the ratio of each case, in the order of the first record of each case.
|
|
32
|
+
* It examines each record. It refuses a case with 2 records of one round.
|
|
33
|
+
* It also refuses a case whose two orders differ in count by more than 1, because that order did not turn each round.
|
|
34
|
+
*/
|
|
35
|
+
function caseRatios(records) {
|
|
36
|
+
const cases = /* @__PURE__ */ new Map();
|
|
37
|
+
for (const record of records) {
|
|
38
|
+
checkPairedTime(record);
|
|
39
|
+
const list = cases.get(record.case) ?? [];
|
|
40
|
+
list.push(record);
|
|
41
|
+
cases.set(record.case, list);
|
|
42
|
+
}
|
|
43
|
+
return [...cases].map(([name, list]) => {
|
|
44
|
+
if (new Set(list.map((r) => r.round)).size !== list.length) throw new RangeError(`caseRatios: the case ${JSON.stringify(name)} has 2 records of one round.`);
|
|
45
|
+
const aFirst = list.filter((r) => r.first === "a").length;
|
|
46
|
+
if (Math.abs(2 * aFirst - list.length) > 1) throw new RangeError(`caseRatios: the case ${JSON.stringify(name)} starts with arm a in ${aFirst} of ${list.length} rounds. The order turns each round.`);
|
|
47
|
+
return {
|
|
48
|
+
case: name,
|
|
49
|
+
ratio: Math.exp(median(list.map((r) => Math.log(r.b / r.a)))),
|
|
50
|
+
rounds: list.length
|
|
51
|
+
};
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
// src/verdict.ts
|
|
55
|
+
/**
|
|
56
|
+
* 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
|
|
57
|
+
* its two arms. Its ratios show how far apart two equal arms come on this machine. A candidate is faster or slower only
|
|
58
|
+
* when its interval is out of that band.
|
|
59
|
+
*/
|
|
60
|
+
/** This function gives the band of the A/A arm. The band is symmetric on a log scale. It refuses fewer cases than `minimum`. */
|
|
61
|
+
function aaBand(aa, options = {}) {
|
|
62
|
+
const ratios = caseRatios(aa);
|
|
63
|
+
const minimum = options.minimum ?? 5;
|
|
64
|
+
if (ratios.length < minimum) throw new RangeError(`aaBand: the A/A arm has ${ratios.length} cases, and a band needs ${minimum} or more.`);
|
|
65
|
+
const logs = ratios.map((r) => Math.log(r.ratio));
|
|
66
|
+
const kind = options.kind ?? "median";
|
|
67
|
+
const level = options.level ?? .95;
|
|
68
|
+
let noise;
|
|
69
|
+
if (kind === "case") noise = quantile(logs.map(Math.abs), level);
|
|
70
|
+
else {
|
|
71
|
+
const interval = bootstrapMedian(logs, {
|
|
72
|
+
...options.bootstrap,
|
|
73
|
+
level
|
|
74
|
+
});
|
|
75
|
+
noise = Math.max(Math.abs(interval.low), Math.abs(interval.high));
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
cases: ratios.length,
|
|
79
|
+
kind,
|
|
80
|
+
noise,
|
|
81
|
+
low: Math.exp(-noise),
|
|
82
|
+
high: Math.exp(noise),
|
|
83
|
+
median: Math.exp(quantile(logs, .5))
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* This function gives the time verdict of the candidate arm `b` against the baseline arm `a`.
|
|
88
|
+
* - The rule `difference` gives `faster` when the whole interval is below 1, and `slower` when it is above 1.
|
|
89
|
+
* It gives `same` when the interval is in `[exp(-margin), exp(margin)]`.
|
|
90
|
+
* - The rule `band` gives `faster` below the band, `slower` above the band, and `same` in the band.
|
|
91
|
+
* - Each other case is `cannot decide`, and so is an A/A arm with too few cases.
|
|
92
|
+
*/
|
|
93
|
+
function timeVerdict(candidate, aa, options = {}) {
|
|
94
|
+
const rule = options.rule ?? "difference";
|
|
95
|
+
const cases = caseRatios(candidate);
|
|
96
|
+
const aaRatios = caseRatios(aa);
|
|
97
|
+
const minimum = options.minimum ?? 5;
|
|
98
|
+
const none = {
|
|
99
|
+
cases,
|
|
100
|
+
rule,
|
|
101
|
+
interval: void 0,
|
|
102
|
+
band: void 0,
|
|
103
|
+
comparison: void 0
|
|
104
|
+
};
|
|
105
|
+
if (cases.length === 0) return {
|
|
106
|
+
...none,
|
|
107
|
+
outcome: "cannot decide",
|
|
108
|
+
reason: "The candidate has no cases."
|
|
109
|
+
};
|
|
110
|
+
if (aaRatios.length < minimum) {
|
|
111
|
+
const interval = bootstrapMedian(cases.map((c) => c.ratio), options.bootstrap);
|
|
112
|
+
return {
|
|
113
|
+
...none,
|
|
114
|
+
interval,
|
|
115
|
+
outcome: "cannot decide",
|
|
116
|
+
reason: `The A/A arm has ${aaRatios.length} cases, and a band needs ${minimum} or more.`
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
const band = aaBand(aa, options);
|
|
120
|
+
const facts = {
|
|
121
|
+
cases,
|
|
122
|
+
rule,
|
|
123
|
+
band,
|
|
124
|
+
comparison: compareRatios(cases.map((c) => 1 + Math.log(c.ratio)), {
|
|
125
|
+
better: "lower",
|
|
126
|
+
noise: band.noise
|
|
127
|
+
})
|
|
128
|
+
};
|
|
129
|
+
if (rule === "difference") {
|
|
130
|
+
const margin = options.margin ?? .05;
|
|
131
|
+
if (!(margin >= 0)) throw new RangeError(`timeVerdict: the margin is 0 or more, not ${margin}.`);
|
|
132
|
+
const logs = cases.map((c) => Math.log(c.ratio));
|
|
133
|
+
const aaLogs = aaRatios.map((c) => Math.log(c.ratio));
|
|
134
|
+
const d = bootstrapTwo(logs, aaLogs, (x, y) => median(x) - median(y), options.bootstrap);
|
|
135
|
+
const interval = {
|
|
136
|
+
...d,
|
|
137
|
+
estimate: Math.exp(d.estimate),
|
|
138
|
+
low: Math.exp(d.low),
|
|
139
|
+
high: Math.exp(d.high)
|
|
140
|
+
};
|
|
141
|
+
const span = `The interval of the candidate median over the A/A median is [${round$1(interval.low)}, ${round$1(interval.high)}].`;
|
|
142
|
+
if (interval.high < 1) return {
|
|
143
|
+
...facts,
|
|
144
|
+
interval,
|
|
145
|
+
outcome: "faster",
|
|
146
|
+
reason: `${span} The interval is below 1.`
|
|
147
|
+
};
|
|
148
|
+
if (interval.low > 1) return {
|
|
149
|
+
...facts,
|
|
150
|
+
interval,
|
|
151
|
+
outcome: "slower",
|
|
152
|
+
reason: `${span} The interval is above 1.`
|
|
153
|
+
};
|
|
154
|
+
if (d.low >= -margin && d.high <= margin) return {
|
|
155
|
+
...facts,
|
|
156
|
+
interval,
|
|
157
|
+
outcome: "same",
|
|
158
|
+
reason: `${span} The interval is in the margin of ${margin}.`
|
|
159
|
+
};
|
|
160
|
+
return {
|
|
161
|
+
...facts,
|
|
162
|
+
interval,
|
|
163
|
+
outcome: "cannot decide",
|
|
164
|
+
reason: `${span} The interval holds 1 and crosses the margin of ${margin}.`
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
const interval = bootstrapMedian(cases.map((c) => c.ratio), options.bootstrap);
|
|
168
|
+
const span = `The interval of the median ratio is [${round$1(interval.low)}, ${round$1(interval.high)}], and the A/A band is [${round$1(band.low)}, ${round$1(band.high)}].`;
|
|
169
|
+
if (interval.high < band.low) return {
|
|
170
|
+
...facts,
|
|
171
|
+
interval,
|
|
172
|
+
outcome: "faster",
|
|
173
|
+
reason: `${span} The interval is below the band.`
|
|
174
|
+
};
|
|
175
|
+
if (interval.low > band.high) return {
|
|
176
|
+
...facts,
|
|
177
|
+
interval,
|
|
178
|
+
outcome: "slower",
|
|
179
|
+
reason: `${span} The interval is above the band.`
|
|
180
|
+
};
|
|
181
|
+
if (interval.low >= band.low && interval.high <= band.high) return {
|
|
182
|
+
...facts,
|
|
183
|
+
interval,
|
|
184
|
+
outcome: "same",
|
|
185
|
+
reason: `${span} The interval is in the band.`
|
|
186
|
+
};
|
|
187
|
+
return {
|
|
188
|
+
...facts,
|
|
189
|
+
interval,
|
|
190
|
+
outcome: "cannot decide",
|
|
191
|
+
reason: `${span} The interval crosses an end of the band.`
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
function round$1(x) {
|
|
195
|
+
return Math.round(x * 1e4) / 1e4;
|
|
196
|
+
}
|
|
197
|
+
// src/limit.ts
|
|
198
|
+
/**
|
|
199
|
+
* 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
|
|
200
|
+
* 2 times the time of the old code" needs it. The time verdict compares only with 1.
|
|
201
|
+
*/
|
|
202
|
+
/**
|
|
203
|
+
* This function gives the ratio of each case with a distribution-free interval of its median, in the order of
|
|
204
|
+
* `caseRatios`. It needs enough rounds for the level: 6 rounds or more for the level 0.95.
|
|
205
|
+
*/
|
|
206
|
+
function caseIntervals(records, level = .95) {
|
|
207
|
+
const logs = /* @__PURE__ */ new Map();
|
|
208
|
+
for (const r of records) {
|
|
209
|
+
const list = logs.get(r.case) ?? [];
|
|
210
|
+
list.push(Math.log(r.b / r.a));
|
|
211
|
+
logs.set(r.case, list);
|
|
212
|
+
}
|
|
213
|
+
return caseRatios(records).map((c) => {
|
|
214
|
+
const interval = medianInterval(logs.get(c.case), level);
|
|
215
|
+
return {
|
|
216
|
+
...c,
|
|
217
|
+
low: Math.exp(interval.low),
|
|
218
|
+
high: Math.exp(interval.high),
|
|
219
|
+
coverage: interval.coverage
|
|
220
|
+
};
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* This function gives the verdict of the claim "the ratio `b / a` of each case is at most `limit`". The A/A band widens
|
|
225
|
+
* the interval of each case: the bound is the high end times the high end of the band.
|
|
226
|
+
* - A case is `within` when its bound is at most the limit, and `beyond` when its floor is above the limit.
|
|
227
|
+
* - The verdict is `beyond` when a case is `beyond`, and `within` when each case is `within`.
|
|
228
|
+
* - Each other verdict is `cannot decide`, and so is an A/A arm with too few cases or a candidate with no cases.
|
|
229
|
+
*/
|
|
230
|
+
function limitVerdict(candidate, aa, options) {
|
|
231
|
+
const { limit } = options;
|
|
232
|
+
if (!(limit > 0 && Number.isFinite(limit))) throw new RangeError(`limitVerdict: the limit is a finite number above 0, not ${limit}.`);
|
|
233
|
+
const intervals = caseIntervals(candidate, options.caseLevel);
|
|
234
|
+
const minimum = options.minimum ?? 5;
|
|
235
|
+
if (intervals.length === 0) return {
|
|
236
|
+
outcome: "cannot decide",
|
|
237
|
+
reason: "The candidate has no cases.",
|
|
238
|
+
limit,
|
|
239
|
+
cases: [],
|
|
240
|
+
band: void 0
|
|
241
|
+
};
|
|
242
|
+
const aaCount = caseRatios(aa).length;
|
|
243
|
+
if (aaCount < minimum) {
|
|
244
|
+
const cases = intervals.map((c) => ({
|
|
245
|
+
...c,
|
|
246
|
+
bound: c.high,
|
|
247
|
+
floor: c.low,
|
|
248
|
+
outcome: "cannot decide"
|
|
249
|
+
}));
|
|
250
|
+
return {
|
|
251
|
+
outcome: "cannot decide",
|
|
252
|
+
reason: `The A/A arm has ${aaCount} cases, and a band needs ${minimum} or more.`,
|
|
253
|
+
limit,
|
|
254
|
+
cases,
|
|
255
|
+
band: void 0
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
const band = aaBand(aa, options);
|
|
259
|
+
const cases = intervals.map((c) => {
|
|
260
|
+
const bound = c.high * band.high;
|
|
261
|
+
const floor = c.low * band.low;
|
|
262
|
+
const outcome = bound <= limit ? "within" : floor > limit ? "beyond" : "cannot decide";
|
|
263
|
+
return {
|
|
264
|
+
...c,
|
|
265
|
+
bound,
|
|
266
|
+
floor,
|
|
267
|
+
outcome
|
|
268
|
+
};
|
|
269
|
+
});
|
|
270
|
+
const top = cases.reduce((a, b) => b.bound > a.bound ? b : a);
|
|
271
|
+
const beyond = cases.filter((c) => c.outcome === "beyond");
|
|
272
|
+
if (beyond.length > 0) return {
|
|
273
|
+
outcome: "beyond",
|
|
274
|
+
reason: `${beyond.length} of ${cases.length} cases are above the limit ${limit}, the first is ${JSON.stringify(beyond[0].case)}.`,
|
|
275
|
+
limit,
|
|
276
|
+
cases,
|
|
277
|
+
band
|
|
278
|
+
};
|
|
279
|
+
if (cases.every((c) => c.outcome === "within")) return {
|
|
280
|
+
outcome: "within",
|
|
281
|
+
reason: `The largest bound is ${round(top.bound)} in the case ${JSON.stringify(top.case)}, and it is at most the limit ${limit}.`,
|
|
282
|
+
limit,
|
|
283
|
+
cases,
|
|
284
|
+
band
|
|
285
|
+
};
|
|
286
|
+
return {
|
|
287
|
+
outcome: "cannot decide",
|
|
288
|
+
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.`,
|
|
289
|
+
limit,
|
|
290
|
+
cases,
|
|
291
|
+
band
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
function round(x) {
|
|
295
|
+
return Math.round(x * 1e4) / 1e4;
|
|
296
|
+
}
|
|
297
|
+
// src/power.ts
|
|
298
|
+
/**
|
|
299
|
+
* The power test of a time verdict. It draws seeded benches with a known speedup and counts the verdicts that find it.
|
|
300
|
+
* It also draws benches with equal arms and counts the false verdicts.
|
|
301
|
+
*/
|
|
302
|
+
/**
|
|
303
|
+
* This function draws `trials` benches and gives the share of each verdict. Each case has its own log scale.
|
|
304
|
+
* Each arm of each round adds a normal noise of `sigma` to the log time.
|
|
305
|
+
*/
|
|
306
|
+
function verdictPower(options) {
|
|
307
|
+
const rounds = options.rounds ?? 5;
|
|
308
|
+
const sigma = options.sigma ?? .1;
|
|
309
|
+
const trials = options.trials ?? 200;
|
|
310
|
+
if (!Number.isSafeInteger(options.cases) || options.cases < 1) throw new RangeError(`verdictPower: cases is a whole number of 1 or more, not ${options.cases}.`);
|
|
311
|
+
if (!(options.ratio > 0 && Number.isFinite(options.ratio))) throw new RangeError(`verdictPower: the ratio is a finite number above 0, not ${options.ratio}.`);
|
|
312
|
+
const r = random(options.seed ?? 1);
|
|
313
|
+
const bench = (ratio, prefix) => {
|
|
314
|
+
const out = [];
|
|
315
|
+
for (let c = 0; c < options.cases; c++) {
|
|
316
|
+
const scale = 10 * Math.exp(r.normal());
|
|
317
|
+
for (let round = 0; round < rounds; round++) {
|
|
318
|
+
const a = scale * Math.exp(r.normal(0, sigma));
|
|
319
|
+
const b = scale * ratio * Math.exp(r.normal(0, sigma));
|
|
320
|
+
out.push({
|
|
321
|
+
case: `${prefix}${c}`,
|
|
322
|
+
round,
|
|
323
|
+
first: firstArm(round, c),
|
|
324
|
+
a,
|
|
325
|
+
b
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
return out;
|
|
330
|
+
};
|
|
331
|
+
const truth = options.ratio < 1 ? "faster" : options.ratio > 1 ? "slower" : "same";
|
|
332
|
+
const counts = {
|
|
333
|
+
faster: 0,
|
|
334
|
+
slower: 0,
|
|
335
|
+
same: 0,
|
|
336
|
+
"cannot decide": 0
|
|
337
|
+
};
|
|
338
|
+
for (let t = 0; t < trials; t++) {
|
|
339
|
+
const aa = bench(1, "aa");
|
|
340
|
+
const candidate = bench(options.ratio, "c");
|
|
341
|
+
counts[timeVerdict(candidate, aa, options.verdict).outcome]++;
|
|
342
|
+
}
|
|
343
|
+
const outcomes = Object.fromEntries(Object.entries(counts).map(([k, n]) => [k, n / trials]));
|
|
344
|
+
return {
|
|
345
|
+
trials,
|
|
346
|
+
outcomes,
|
|
347
|
+
power: outcomes[truth]
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
// src/rounds.ts
|
|
351
|
+
/**
|
|
352
|
+
* 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
|
|
353
|
+
* one batch grows until a batch of arm `a` takes the target time. Each round times one batch of each arm, in the order
|
|
354
|
+
* of `firstArm`. Start this function in a fresh process for each case.
|
|
355
|
+
*/
|
|
356
|
+
/**
|
|
357
|
+
* This function times the arms `a` and `b` of one case, and gives one `PairedTime` record for each round. The time of
|
|
358
|
+
* a record is the time of one batch, in milliseconds. Each call of an arm gives a number, and the sum of these numbers
|
|
359
|
+
* keeps the work.
|
|
360
|
+
*/
|
|
361
|
+
function timeRounds(arms, options) {
|
|
362
|
+
const { rounds } = options;
|
|
363
|
+
const offset = options.offset ?? 0;
|
|
364
|
+
const targetMs = options.targetMs ?? 10;
|
|
365
|
+
const warmMs = options.warmMs ?? 1e3;
|
|
366
|
+
const now = options.now ?? (() => performance.now());
|
|
367
|
+
if (!Number.isSafeInteger(rounds) || rounds < 1) throw new RangeError(`timeRounds: the rounds are a whole number of 1 or more, not ${rounds}.`);
|
|
368
|
+
if (!Number.isSafeInteger(offset)) throw new RangeError(`timeRounds: the offset is a whole number, not ${offset}.`);
|
|
369
|
+
if (!(targetMs > 0) || !(warmMs >= 0)) throw new RangeError("timeRounds: the target time is above 0, and the warm-up time is 0 or more.");
|
|
370
|
+
let sink = 0;
|
|
371
|
+
const batch = (arm, count) => {
|
|
372
|
+
const run = arms[arm];
|
|
373
|
+
const start = now();
|
|
374
|
+
for (let i = 0; i < count; i++) sink += run();
|
|
375
|
+
return now() - start;
|
|
376
|
+
};
|
|
377
|
+
let count = 1;
|
|
378
|
+
const warmUntil = now() + warmMs;
|
|
379
|
+
while (now() < warmUntil) {
|
|
380
|
+
if (batch("a", count) < targetMs / 4) count *= 2;
|
|
381
|
+
batch("b", count);
|
|
382
|
+
}
|
|
383
|
+
while (batch("a", count) < targetMs) count *= 2;
|
|
384
|
+
const records = [];
|
|
385
|
+
for (let round = 0; round < rounds; round++) {
|
|
386
|
+
const first = firstArm(round, offset);
|
|
387
|
+
const second = first === "a" ? "b" : "a";
|
|
388
|
+
const times = {
|
|
389
|
+
[first]: batch(first, count),
|
|
390
|
+
[second]: batch(second, count)
|
|
391
|
+
};
|
|
392
|
+
records.push({
|
|
393
|
+
case: options.case,
|
|
394
|
+
round,
|
|
395
|
+
first,
|
|
396
|
+
a: times.a,
|
|
397
|
+
b: times.b
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
return {
|
|
401
|
+
records,
|
|
402
|
+
count,
|
|
403
|
+
sink
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
export { aaBand, caseIntervals, caseRatios, checkPairedTime, firstArm, limitVerdict, timeRounds, timeVerdict, verdictPower };
|
|
407
|
+
|
|
408
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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/** 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\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}\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 */\nexport function timeVerdict(candidate: readonly PairedTime[], aa: readonly PairedTime[], options: VerdictOptions = {}): 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 = 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 = options.margin ?? 0.05;\n if (!(margin >= 0)) throw new RangeError(`timeVerdict: the margin is 0 or more, not ${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 ${margin}.` };\n return { ...facts, interval, outcome: \"cannot decide\", reason: `${span} The interval holds 1 and crosses the margin of ${margin}.` };\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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O,EAAE;CAClH,IAAI,EAAE,WAAW,MAAM,EAAE,UAAU,IAAI,MAAM,IAAI,WAAW,4EAA4E;CACxI,IAAI,OAAO;CACX,MAAM,SAAS,KAAU,UAA0B;EACjD,MAAM,MAAM,KAAK;EACjB,MAAM,QAAQ,IAAI;EAClB,KAAK,IAAI,IAAI,GAAG,IAAI,OAAO,KAAK,QAAQ,IAAI;EAC5C,OAAO,IAAI,IAAI;CACjB;CACA,IAAI,QAAQ;CACZ,MAAM,YAAY,IAAI,IAAI;CAC1B,OAAO,IAAI,IAAI,WAAW;EACxB,IAAI,MAAM,KAAK,KAAK,IAAI,WAAW,GAAG,SAAS;EAC/C,MAAM,KAAK,KAAK;CAClB;CACA,OAAO,MAAM,KAAK,KAAK,IAAI,UAAU,SAAS;CAC9C,MAAM,UAAwB,CAAC;CAC/B,KAAK,IAAI,QAAQ,GAAG,QAAQ,QAAQ,SAAS;EAC3C,MAAM,QAAQ,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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,62 @@
|
|
|
1
1
|
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/package",
|
|
2
3
|
"name": "@mark1russell7/rigor-bench",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
4
|
+
"version": "0.1.1",
|
|
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
|
+
"keywords": [
|
|
7
|
+
"benchmark",
|
|
8
|
+
"paired",
|
|
9
|
+
"a/a",
|
|
10
|
+
"noise",
|
|
11
|
+
"bootstrap",
|
|
12
|
+
"performance",
|
|
13
|
+
"timing"
|
|
14
|
+
],
|
|
15
|
+
"homepage": "https://github.com/mark1russell7/rigor/tree/main/packages/bench#readme",
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/mark1russell7/rigor/issues"
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/mark1russell7/rigor.git",
|
|
22
|
+
"directory": "packages/bench"
|
|
23
|
+
},
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"author": "Mark Russell (https://github.com/mark1russell7)",
|
|
26
|
+
"type": "module",
|
|
27
|
+
"main": "./build/index.js",
|
|
28
|
+
"files": [
|
|
29
|
+
"build"
|
|
30
|
+
],
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public"
|
|
33
|
+
},
|
|
34
|
+
"engines": {
|
|
35
|
+
"node": ">=22"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@mark1russell7/rigor-statistics": "^0.1.5"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@mark1russell7/rigor-generators": "^0.1.1",
|
|
42
|
+
"@mark1russell7/cue": "^1.0.2",
|
|
43
|
+
"@types/node": "^26.6.5",
|
|
44
|
+
"tsdown": "^0.23.1",
|
|
45
|
+
"typescript": "^7.0.2",
|
|
46
|
+
"vitest": "^5.0.3"
|
|
47
|
+
},
|
|
48
|
+
"scripts": {
|
|
49
|
+
"build": "tsdown",
|
|
50
|
+
"test": "vitest run",
|
|
51
|
+
"test:watch": "vitest",
|
|
52
|
+
"typecheck": "tsc -p tsconfig.json && tsc -p tsconfig.test.json"
|
|
53
|
+
},
|
|
54
|
+
"types": "./build/index.d.ts",
|
|
55
|
+
"exports": {
|
|
56
|
+
".": {
|
|
57
|
+
"types": "./build/index.d.ts",
|
|
58
|
+
"import": "./build/index.js"
|
|
59
|
+
},
|
|
60
|
+
"./package.json": "./package.json"
|
|
61
|
+
}
|
|
6
62
|
}
|