@ac-bench/lib
Functions
Classes
Constants
Interfaces
Types
baselineLocation(reference: string, fingerprintId: string, directory?: string): string
Where a baseline is filed: a path as given (resolved against the working
directory), a name as <directory>/<fingerprint id>/<name>.json, so each
environment keeps its own baselines under one name.
benchFileLabel(file: string, cwd?: string, paths?: Pick<typeof path.win32, "relative" | "isAbsolute" | "sep">): string
The path a run records for a bench file, and the file part of every key:
relative to the working directory, /-separated, so it is the same from any
checkout location.
Throws When file has no relative path from cwd
(another Windows drive or share).
Parameters
pathsThe path flavour, the platform’s by default.
captureEnvironmentBaseline(probe: EnvironmentProbe, windowMs: number, intervalMs?: number, signal?: AbortSignal): Promise<EnvironmentBaseline>
Samples over windowMs are the reference every later gate compares against.
classifyEnvironment(samples: readonly EnvironmentSample[]): EnvironmentVerdict
Classifies a scripted or collected series.
A monotone ramp and an oscillation of the same amplitude look identical to a
variance threshold and mean completely different things, so the two tests are
separated: mannKendallTrend answers “is it going somewhere” and
reversalRate answers “does it keep changing its mind”.
comparisonUnresolved(frame: DataFrame, comparison: MeasureComparison | undefined): boolean
Whether the measurements taken so far settle the comparison.
A benchmark’s job is to order its cases. Two cases whose intervals overlap
are not ordered by the numbers: whichever came out ahead did so within the
noise, and another process could reverse it. That is the only signal worth
spending more machine time on, and it is measure-agnostic — the parent reads
it off the frame and the comparison every plugin already declares, rather
than knowing what any measure’s numbers mean.
Cases without an interval are ignored: an unknown interval is not an
overlapping one, and treating it as such would escalate forever.
O(n log n) in the case count, for the sort.
Returns true when some adjacent pair cannot be told apart.
Parameters
frameThe condition’s frame, from MeasurePlugin.conditionFrame.
comparisonWhat the measure says orders its cases. A measure with no
interval bounds makes no claim tight enough to escalate on.
createMeasureDiagnosticProxy(inner: ISink<{
conditionTitle: string;
kind: "condition-result";
measure: string;
result: unknown;
} | {
arm: "shared" | "isolated";
caseTitle: string;
kind: "case-execution";
measure: string;
replicate: number;
result: unknown;
} | {
caseTitle: string;
kind: "case-result";
measure: string;
result: unknown;
} | {
file: string;
kind: "load-error";
message: string;
} | {
kind: "run-description";
machine: {
architecture: string;
availableParallelism: number;
cpuGovernor: string | null;
cpuModel: string;
kernelRelease: string;
logicalCores: number;
memoryGiB: number;
os: string;
physicalCores: number | null;
};
run: {
argv: string[];
id: string;
mode: string | null;
orderSeed: number;
plan: {
cooldown: boolean;
isolatedRuns: number;
maxReplicates: number;
replicates: number;
retryOnInstability: number;
rounds: number;
};
startedAt: string;
tool: {
name: "@ac-bench/lib";
version: string;
};
};
} | {
kind: "runtime-description";
runtime: {
capabilities: {
allocationCounter: "v8-total-allocated" | "gc-profiler" | "heap-growth" | "browser-heap-growth" | null;
cpuTime: boolean;
forcedCollection: boolean;
};
clock: {
readCostMs: number;
resolutionMs: number;
source: "performance.now";
};
crossOriginIsolated: boolean | null;
device: {
model: string;
os: string;
osVersion: string;
} | null;
engine: "v8" | "spidermonkey" | "javascriptcore";
flags: string[];
headless: boolean | null;
id: string;
isolation: "browser" | "process" | "context" | "reload";
kind: "node" | "browser";
product: string;
userAgent: string | null;
version: string;
};
} | {
gate: {
conditionPath: number[];
declaration: {
denominators: string[];
id?: string;
kind: "ratio";
max?: number;
maxDispersion?: number;
metric?: string;
min?: number;
numerator: string;
rationale?: string;
runtimes?: string[];
} | {
id?: string;
kind: "difference";
max?: number;
maxDispersion?: number;
metric?: string;
min?: number;
rationale?: string;
reference: string;
runtimes?: string[];
subject: string;
} | {
id?: string;
kind: "bound";
max?: number;
maxDispersion?: number;
metric?: string;
min?: number;
rationale?: string;
runtimes?: string[];
subject: string;
};
file: string;
origin: "suite";
} | {
declaration: {
denominators: (string | {
case: string;
condition: ... | ...;
file?: ... | ...;
} | {
case: string;
})[];
id?: string;
kind: "ratio";
max?: number;
maxDispersion?: number;
metric?: string;
min?: number;
numerator: string | {
case: string;
condition: string | ...[];
file?: string;
} | {
case: string;
};
rationale?: string;
runtimes?: string[];
} | {
id?: string;
kind: "difference";
max?: number;
maxDispersion?: number;
metric?: string;
min?: number;
rationale?: string;
reference: string | {
case: string;
condition: string | ...[];
file?: string;
} | {
case: string;
};
runtimes?: string[];
subject: string | {
case: string;
condition: string | ...[];
file?: string;
} | {
case: string;
};
} | {
id?: string;
kind: "bound";
max?: number;
maxDispersion?: number;
metric?: string;
min?: number;
rationale?: string;
runtimes?: string[];
subject: string | {
case: string;
condition: string | ...[];
file?: string;
} | {
case: string;
};
} | {
id?: string;
kind: "baseline";
maxDispersion?: number;
maxRegression?: number;
metric?: string;
normalizeBy?: string | {
case: string;
condition: string | ...[];
file?: string;
} | {
case: string;
};
rationale?: string;
runtimes?: string[];
subjects?: (string | {
case: ...;
condition: ...;
file?: ...;
} | {
case: ...;
})[];
};
origin: "config" | "cli";
};
kind: "gate-declaration";
} | {
kind: "gate-verdict";
verdict: {
adjustedPValue: number | null;
degreesOfFreedom: number | null;
dispersion: number | null;
escalatedReplicates: number;
estimate: number | null;
estimator: "paired" | "unpaired" | "single" | null;
executions: number[];
id: string;
interval: {
level: number;
lower: number;
upper: number;
} | null;
kind: "ratio" | "difference" | "bound" | "baseline";
message: string;
metric: {
direction: "lower-is-better" | "higher-is-better";
name: string;
scale: "log" | "linear";
unit: {
scale: number;
symbol: string;
};
};
origin: "suite" | "config" | "cli";
pValue: number | null;
rationale?: string;
reason: "decided" | "interval-contains-threshold" | "multiplicity" | "dispersion-exceeds-limit" | "too-few-executions" | "no-threshold" | "case-failed" | "case-filtered" | "metric-unavailable" | "non-positive-value" | "runtime-unsupported" | "runtime-unavailable" | "baseline-case-missing" | "baseline-environment-mismatch";
runtime: string;
subjects: {
caseTitle: string;
conditionTitles: string[];
file: string;
runtime: string;
}[];
threshold: {
max?: number;
min?: number;
};
verdict: "error" | "pass" | "fail" | "inconclusive" | "reported" | "skipped" | "not-applicable" | "incomparable";
};
} | {
completedUnits: number;
kind: "run-progress";
totalUnits: number;
} | {
cases: {
selected: boolean;
title: string;
}[];
conditionPath: number[];
file: string;
kind: "unit-declaration";
measure: string;
runtime: string;
titles: string[];
}>, registry: MeasureRegistry): ISink<{
conditionTitle: string;
kind: "condition-result";
measure: string;
result: unknown;
} | {
arm: "shared" | "isolated";
caseTitle: string;
kind: "case-execution";
measure: string;
replicate: number;
result: unknown;
} | {
caseTitle: string;
kind: "case-result";
measure: string;
result: unknown;
} | {
file: string;
kind: "load-error";
message: string;
} | {
kind: "run-description";
machine: {
architecture: string;
availableParallelism: number;
cpuGovernor: string | null;
cpuModel: string;
kernelRelease: string;
logicalCores: number;
memoryGiB: number;
os: string;
physicalCores: number | null;
};
run: {
argv: string[];
id: string;
mode: string | null;
orderSeed: number;
plan: {
cooldown: boolean;
isolatedRuns: number;
maxReplicates: number;
replicates: number;
retryOnInstability: number;
rounds: number;
};
startedAt: string;
tool: {
name: "@ac-bench/lib";
version: string;
};
};
} | {
kind: "runtime-description";
runtime: {
capabilities: {
allocationCounter: "v8-total-allocated" | "gc-profiler" | "heap-growth" | "browser-heap-growth" | null;
cpuTime: boolean;
forcedCollection: boolean;
};
clock: {
readCostMs: number;
resolutionMs: number;
source: "performance.now";
};
crossOriginIsolated: boolean | null;
device: {
model: string;
os: string;
osVersion: string;
} | null;
engine: "v8" | "spidermonkey" | "javascriptcore";
flags: string[];
headless: boolean | null;
id: string;
isolation: "browser" | "process" | "context" | "reload";
kind: "node" | "browser";
product: string;
userAgent: string | null;
version: string;
};
} | {
gate: {
conditionPath: number[];
declaration: {
denominators: string[];
id?: string;
kind: "ratio";
max?: number;
maxDispersion?: number;
metric?: string;
min?: number;
numerator: string;
rationale?: string;
runtimes?: string[];
} | {
id?: string;
kind: "difference";
max?: number;
maxDispersion?: number;
metric?: string;
min?: number;
rationale?: string;
reference: string;
runtimes?: string[];
subject: string;
} | {
id?: string;
kind: "bound";
max?: number;
maxDispersion?: number;
metric?: string;
min?: number;
rationale?: string;
runtimes?: string[];
subject: string;
};
file: string;
origin: "suite";
} | {
declaration: {
denominators: (string | {
case: string;
condition: ... | ...;
file?: ... | ...;
} | {
case: string;
})[];
id?: string;
kind: "ratio";
max?: number;
maxDispersion?: number;
metric?: string;
min?: number;
numerator: string | {
case: string;
condition: string | ...[];
file?: string;
} | {
case: string;
};
rationale?: string;
runtimes?: string[];
} | {
id?: string;
kind: "difference";
max?: number;
maxDispersion?: number;
metric?: string;
min?: number;
rationale?: string;
reference: string | {
case: string;
condition: string | ...[];
file?: string;
} | {
case: string;
};
runtimes?: string[];
subject: string | {
case: string;
condition: string | ...[];
file?: string;
} | {
case: string;
};
} | {
id?: string;
kind: "bound";
max?: number;
maxDispersion?: number;
metric?: string;
min?: number;
rationale?: string;
runtimes?: string[];
subject: string | {
case: string;
condition: string | ...[];
file?: string;
} | {
case: string;
};
} | {
id?: string;
kind: "baseline";
maxDispersion?: number;
maxRegression?: number;
metric?: string;
normalizeBy?: string | {
case: string;
condition: string | ...[];
file?: string;
} | {
case: string;
};
rationale?: string;
runtimes?: string[];
subjects?: (string | {
case: ...;
condition: ...;
file?: ...;
} | {
case: ...;
})[];
};
origin: "config" | "cli";
};
kind: "gate-declaration";
} | {
kind: "gate-verdict";
verdict: {
adjustedPValue: number | null;
degreesOfFreedom: number | null;
dispersion: number | null;
escalatedReplicates: number;
estimate: number | null;
estimator: "paired" | "unpaired" | "single" | null;
executions: number[];
id: string;
interval: {
level: number;
lower: number;
upper: number;
} | null;
kind: "ratio" | "difference" | "bound" | "baseline";
message: string;
metric: {
direction: "lower-is-better" | "higher-is-better";
name: string;
scale: "log" | "linear";
unit: {
scale: number;
symbol: string;
};
};
origin: "suite" | "config" | "cli";
pValue: number | null;
rationale?: string;
reason: "decided" | "interval-contains-threshold" | "multiplicity" | "dispersion-exceeds-limit" | "too-few-executions" | "no-threshold" | "case-failed" | "case-filtered" | "metric-unavailable" | "non-positive-value" | "runtime-unsupported" | "runtime-unavailable" | "baseline-case-missing" | "baseline-environment-mismatch";
runtime: string;
subjects: {
caseTitle: string;
conditionTitles: string[];
file: string;
runtime: string;
}[];
threshold: {
max?: number;
min?: number;
};
verdict: "error" | "pass" | "fail" | "inconclusive" | "reported" | "skipped" | "not-applicable" | "incomparable";
};
} | {
completedUnits: number;
kind: "run-progress";
totalUnits: number;
} | {
cases: {
selected: boolean;
title: string;
}[];
conditionPath: number[];
file: string;
kind: "unit-declaration";
measure: string;
runtime: string;
titles: string[];
}>
Derives the generic diagnostic events from a measure’s typed warnings, in
the parent.
Warnings live in the typed result, where the plugin renders them inline per
row; generic sinks need them as severity-carrying events. Emitting both from
the child would give one fact two sources of truth, so the translation
happens here instead — right after the data event that carries the result
and before the case’s scope-end.
createReporterContext(registry: MeasureRegistry, options?: ReporterContextOptions): ReporterContext
Assembles the host-bound half of reporting, so a reporter package needs no
node: import of its own.
currentEnvironment(): {
arch: string;
platform: string;
runtime: string;
timestamp: string;
}
Environment captured at run time, carried into live tables and exports.
defaultArtifactCacheRoot(): string
node_modules/.cache/ac-bench, relative to where the CLI was invoked.
defaultBaselineDirectory(cwd?: string): string
node_modules/.cache/ac-bench/baselines, under the working directory: never
committed.
defineRuntimePlugin(spec: Omit<RuntimePlugin, typeof RUNTIME_PLUGIN_TAG>): RuntimePlugin
describeMachine(sysfsRoot?: string): Promise<{
architecture: string;
availableParallelism: number;
cpuGovernor: string | null;
cpuModel: string;
kernelRelease: string;
logicalCores: number;
memoryGiB: number;
os: string;
physicalCores: number | null;
}>
What a reader needs to tell two machines apart: CPU, memory, OS, governor. No
host name, no user name.
describeRuntime(launch: ReturnType<ExecutionRuntime["describe"]>, environment: {
capabilities: {
allocationCounter: "v8-total-allocated" | "gc-profiler" | "heap-growth" | "browser-heap-growth" | null;
cpuTime: boolean;
forcedCollection: boolean;
};
clock: {
readCostMs: number;
resolutionMs: number;
source: "performance.now";
};
crossOriginIsolated: boolean | null;
engineVersion: string;
userAgent: string | null;
}, measured?: {
readonly flags?: readonly string[];
readonly forcedCollection?: boolean;
}): {
capabilities: {
allocationCounter: "v8-total-allocated" | "gc-profiler" | "heap-growth" | "browser-heap-growth" | null;
cpuTime: boolean;
forcedCollection: boolean;
};
clock: {
readCostMs: number;
resolutionMs: number;
source: "performance.now";
};
crossOriginIsolated: boolean | null;
device: {
model: string;
os: string;
osVersion: string;
} | null;
engine: "v8" | "spidermonkey" | "javascriptcore";
flags: string[];
headless: boolean | null;
id: string;
isolation: "browser" | "process" | "context" | "reload";
kind: "node" | "browser";
product: string;
userAgent: string | null;
version: string;
}
A runtime’s full description: what its launcher knows, completed by what a
child measured of itself in its hello.
Parameters
launchThe runtime’s describe().
environmentA child’s hello environment.
measuredWhat the run’s measuring children add: the switches their
measures asked for, after the runtime’s own (both as given, in order and
with their repetitions, since --import and the like act once each), and
whether any of them could force a collection.
discoverConditionsInFile(file: string, options?: ForkOptions): Promise<DiscoveredCondition[]>
Starts a discovery child for file and returns the condition tree it
registered, without executing a single case.
discoveredCaseTitles(condition: DiscoveredCondition, start?: number, end?: number): string[]
The cases condition declared directly, within an optional entry range.
discoveredChildren(condition: DiscoveredCondition): [number, DiscoveredCondition][]
The conditions condition declared directly, each with its entry index.
isBaselinePath(reference: string): boolean
Whether reference is a path rather than a name: it holds a / (or the
platform’s separator) or ends with .json.
isRuntimePlugin(value: unknown): value is RuntimePlugin
A branded runtime plugin this package can create a runtime from.
loadBaseline(reference: string, current: Pick<BenchArchive, "machine" | "runtimes" | "run">, directory?: string): Promise<BenchArchive>
Reads a baseline: a path as given, a name in the directory of current’s
fingerprint.
Throws When the file is missing or not a bench archive; for
a name filed only under other environments, the message lists their files
(compare with one through its path and allowForeignBaseline).
nodeEnvironmentProbe(options?: NodeEnvironmentProbeOptions): EnvironmentProbe
Reads the host metrics this platform exposes; unreadable ones are null.
nodeRuntime(options?: NodeRuntimeOptions): RuntimePlugin
The runtime every run measures in unless another is selected: each child is a
Node process forked from this one, running @ac-bench/lib/child.
resolveConditionRounds(scheduling: MeasureScheduling, requested: number | undefined): number
A measure declaring rounds: "one" refuses round-robin interleaving whatever
the run asks for; the scheduler reads the declaration and never the measure
id.
runBench(files: readonly string[], measures: readonly MeasurePlugin[], reporters: readonly ReporterPlugin[], options?: BenchRunOptions): Promise<BenchRunOutcome>
Discovers every bench file’s condition tree in every runtime first, then
measures each fork unit in a child of its own, runtime after runtime, closing
every sink once the last one finishes.
With more than one runtime, or a single one other than Node, every runtime
gets a scope of its own (titled by product and version, keyed and attributed
by its id) and every key carries the runtime’s id; a Node-only run keeps the
scope tree and the keys it always had.
When signal aborts, the in-flight child is terminated, every condition not
yet started is skipped, and the sinks are still closed.
A file that fails to load is reported to stderr as a load-error and
skipped — the run continues with the next file rather than crashing over one
broken bench file. A runtime that cannot be created or prepared is reported
as a runtime-failed error and skipped the same way.
Throws Before anything runs, when a file has no
path relative to the working directory (another Windows drive or share),
since its results could not be keyed the same on another machine.
Throws Before anything runs, when runtimes is empty or names
one id twice.
Parameters
filesBench files to run, already discovered.
measuresRegistered for the measures files declare conditions for.
reportersEvery reporter the run reports to; each sink is closed when
it ends.
runDiscoveredFile(file: string, conditions: readonly DiscoveredCondition[], sink: ISink<{
conditionTitle: string;
kind: "condition-result";
measure: string;
result: unknown;
} | {
arm: "shared" | "isolated";
caseTitle: string;
kind: "case-execution";
measure: string;
replicate: number;
result: unknown;
} | {
caseTitle: string;
kind: "case-result";
measure: string;
result: unknown;
} | {
file: string;
kind: "load-error";
message: string;
} | {
kind: "run-description";
machine: {
architecture: string;
availableParallelism: number;
cpuGovernor: string | null;
cpuModel: string;
kernelRelease: string;
logicalCores: number;
memoryGiB: number;
os: string;
physicalCores: number | null;
};
run: {
argv: string[];
id: string;
mode: string | null;
orderSeed: number;
plan: {
cooldown: boolean;
isolatedRuns: number;
maxReplicates: number;
replicates: number;
retryOnInstability: number;
rounds: number;
};
startedAt: string;
tool: {
name: "@ac-bench/lib";
version: string;
};
};
} | {
kind: "runtime-description";
runtime: {
capabilities: {
allocationCounter: "v8-total-allocated" | "gc-profiler" | "heap-growth" | "browser-heap-growth" | null;
cpuTime: boolean;
forcedCollection: boolean;
};
clock: {
readCostMs: number;
resolutionMs: number;
source: "performance.now";
};
crossOriginIsolated: boolean | null;
device: {
model: string;
os: string;
osVersion: string;
} | null;
engine: "v8" | "spidermonkey" | "javascriptcore";
flags: string[];
headless: boolean | null;
id: string;
isolation: "browser" | "process" | "context" | "reload";
kind: "node" | "browser";
product: string;
userAgent: string | null;
version: string;
};
} | {
gate: {
conditionPath: number[];
declaration: {
denominators: string[];
id?: string;
kind: "ratio";
max?: number;
maxDispersion?: number;
metric?: string;
min?: number;
numerator: string;
rationale?: string;
runtimes?: string[];
} | {
id?: string;
kind: "difference";
max?: number;
maxDispersion?: number;
metric?: string;
min?: number;
rationale?: string;
reference: string;
runtimes?: string[];
subject: string;
} | {
id?: string;
kind: "bound";
max?: number;
maxDispersion?: number;
metric?: string;
min?: number;
rationale?: string;
runtimes?: string[];
subject: string;
};
file: string;
origin: "suite";
} | {
declaration: {
denominators: (string | {
case: string;
condition: ... | ...;
file?: ... | ...;
} | {
case: string;
})[];
id?: string;
kind: "ratio";
max?: number;
maxDispersion?: number;
metric?: string;
min?: number;
numerator: string | {
case: string;
condition: string | ...[];
file?: string;
} | {
case: string;
};
rationale?: string;
runtimes?: string[];
} | {
id?: string;
kind: "difference";
max?: number;
maxDispersion?: number;
metric?: string;
min?: number;
rationale?: string;
reference: string | {
case: string;
condition: string | ...[];
file?: string;
} | {
case: string;
};
runtimes?: string[];
subject: string | {
case: string;
condition: string | ...[];
file?: string;
} | {
case: string;
};
} | {
id?: string;
kind: "bound";
max?: number;
maxDispersion?: number;
metric?: string;
min?: number;
rationale?: string;
runtimes?: string[];
subject: string | {
case: string;
condition: string | ...[];
file?: string;
} | {
case: string;
};
} | {
id?: string;
kind: "baseline";
maxDispersion?: number;
maxRegression?: number;
metric?: string;
normalizeBy?: string | {
case: string;
condition: string | ...[];
file?: string;
} | {
case: string;
};
rationale?: string;
runtimes?: string[];
subjects?: (string | {
case: ...;
condition: ...;
file?: ...;
} | {
case: ...;
})[];
};
origin: "config" | "cli";
};
kind: "gate-declaration";
} | {
kind: "gate-verdict";
verdict: {
adjustedPValue: number | null;
degreesOfFreedom: number | null;
dispersion: number | null;
escalatedReplicates: number;
estimate: number | null;
estimator: "paired" | "unpaired" | "single" | null;
executions: number[];
id: string;
interval: {
level: number;
lower: number;
upper: number;
} | null;
kind: "ratio" | "difference" | "bound" | "baseline";
message: string;
metric: {
direction: "lower-is-better" | "higher-is-better";
name: string;
scale: "log" | "linear";
unit: {
scale: number;
symbol: string;
};
};
origin: "suite" | "config" | "cli";
pValue: number | null;
rationale?: string;
reason: "decided" | "interval-contains-threshold" | "multiplicity" | "dispersion-exceeds-limit" | "too-few-executions" | "no-threshold" | "case-failed" | "case-filtered" | "metric-unavailable" | "non-positive-value" | "runtime-unsupported" | "runtime-unavailable" | "baseline-case-missing" | "baseline-environment-mismatch";
runtime: string;
subjects: {
caseTitle: string;
conditionTitles: string[];
file: string;
runtime: string;
}[];
threshold: {
max?: number;
min?: number;
};
verdict: "error" | "pass" | "fail" | "inconclusive" | "reported" | "skipped" | "not-applicable" | "incomparable";
};
} | {
completedUnits: number;
kind: "run-progress";
totalUnits: number;
} | {
cases: {
selected: boolean;
title: string;
}[];
conditionPath: number[];
file: string;
kind: "unit-declaration";
measure: string;
runtime: string;
titles: string[];
}>, registry: MeasureRegistry, options?: IsolatedRunOptions): Promise<void>
Runs every executable leaf of an already discovered file in a child of its
own, as runFileIsolated does once discovery is over.
A leaf whose measure does not run in options.runtimeDescription
(supportsRuntime) forks nothing: its scope is skipped with the reason, a
runtime-unsupported warning, and every selected case archived
"unsupported".
Parameters
conditionsWhat a discovery child returned for file.
runFileIsolated(file: string, sink: ISink<{
conditionTitle: string;
kind: "condition-result";
measure: string;
result: unknown;
} | {
arm: "shared" | "isolated";
caseTitle: string;
kind: "case-execution";
measure: string;
replicate: number;
result: unknown;
} | {
caseTitle: string;
kind: "case-result";
measure: string;
result: unknown;
} | {
file: string;
kind: "load-error";
message: string;
} | {
kind: "run-description";
machine: {
architecture: string;
availableParallelism: number;
cpuGovernor: string | null;
cpuModel: string;
kernelRelease: string;
logicalCores: number;
memoryGiB: number;
os: string;
physicalCores: number | null;
};
run: {
argv: string[];
id: string;
mode: string | null;
orderSeed: number;
plan: {
cooldown: boolean;
isolatedRuns: number;
maxReplicates: number;
replicates: number;
retryOnInstability: number;
rounds: number;
};
startedAt: string;
tool: {
name: "@ac-bench/lib";
version: string;
};
};
} | {
kind: "runtime-description";
runtime: {
capabilities: {
allocationCounter: "v8-total-allocated" | "gc-profiler" | "heap-growth" | "browser-heap-growth" | null;
cpuTime: boolean;
forcedCollection: boolean;
};
clock: {
readCostMs: number;
resolutionMs: number;
source: "performance.now";
};
crossOriginIsolated: boolean | null;
device: {
model: string;
os: string;
osVersion: string;
} | null;
engine: "v8" | "spidermonkey" | "javascriptcore";
flags: string[];
headless: boolean | null;
id: string;
isolation: "browser" | "process" | "context" | "reload";
kind: "node" | "browser";
product: string;
userAgent: string | null;
version: string;
};
} | {
gate: {
conditionPath: number[];
declaration: {
denominators: string[];
id?: string;
kind: "ratio";
max?: number;
maxDispersion?: number;
metric?: string;
min?: number;
numerator: string;
rationale?: string;
runtimes?: string[];
} | {
id?: string;
kind: "difference";
max?: number;
maxDispersion?: number;
metric?: string;
min?: number;
rationale?: string;
reference: string;
runtimes?: string[];
subject: string;
} | {
id?: string;
kind: "bound";
max?: number;
maxDispersion?: number;
metric?: string;
min?: number;
rationale?: string;
runtimes?: string[];
subject: string;
};
file: string;
origin: "suite";
} | {
declaration: {
denominators: (string | {
case: string;
condition: ... | ...;
file?: ... | ...;
} | {
case: string;
})[];
id?: string;
kind: "ratio";
max?: number;
maxDispersion?: number;
metric?: string;
min?: number;
numerator: string | {
case: string;
condition: string | ...[];
file?: string;
} | {
case: string;
};
rationale?: string;
runtimes?: string[];
} | {
id?: string;
kind: "difference";
max?: number;
maxDispersion?: number;
metric?: string;
min?: number;
rationale?: string;
reference: string | {
case: string;
condition: string | ...[];
file?: string;
} | {
case: string;
};
runtimes?: string[];
subject: string | {
case: string;
condition: string | ...[];
file?: string;
} | {
case: string;
};
} | {
id?: string;
kind: "bound";
max?: number;
maxDispersion?: number;
metric?: string;
min?: number;
rationale?: string;
runtimes?: string[];
subject: string | {
case: string;
condition: string | ...[];
file?: string;
} | {
case: string;
};
} | {
id?: string;
kind: "baseline";
maxDispersion?: number;
maxRegression?: number;
metric?: string;
normalizeBy?: string | {
case: string;
condition: string | ...[];
file?: string;
} | {
case: string;
};
rationale?: string;
runtimes?: string[];
subjects?: (string | {
case: ...;
condition: ...;
file?: ...;
} | {
case: ...;
})[];
};
origin: "config" | "cli";
};
kind: "gate-declaration";
} | {
kind: "gate-verdict";
verdict: {
adjustedPValue: number | null;
degreesOfFreedom: number | null;
dispersion: number | null;
escalatedReplicates: number;
estimate: number | null;
estimator: "paired" | "unpaired" | "single" | null;
executions: number[];
id: string;
interval: {
level: number;
lower: number;
upper: number;
} | null;
kind: "ratio" | "difference" | "bound" | "baseline";
message: string;
metric: {
direction: "lower-is-better" | "higher-is-better";
name: string;
scale: "log" | "linear";
unit: {
scale: number;
symbol: string;
};
};
origin: "suite" | "config" | "cli";
pValue: number | null;
rationale?: string;
reason: "decided" | "interval-contains-threshold" | "multiplicity" | "dispersion-exceeds-limit" | "too-few-executions" | "no-threshold" | "case-failed" | "case-filtered" | "metric-unavailable" | "non-positive-value" | "runtime-unsupported" | "runtime-unavailable" | "baseline-case-missing" | "baseline-environment-mismatch";
runtime: string;
subjects: {
caseTitle: string;
conditionTitles: string[];
file: string;
runtime: string;
}[];
threshold: {
max?: number;
min?: number;
};
verdict: "error" | "pass" | "fail" | "inconclusive" | "reported" | "skipped" | "not-applicable" | "incomparable";
};
} | {
completedUnits: number;
kind: "run-progress";
totalUnits: number;
} | {
cases: {
selected: boolean;
title: string;
}[];
conditionPath: number[];
file: string;
kind: "unit-declaration";
measure: string;
runtime: string;
titles: string[];
}>, registry: MeasureRegistry, options?: IsolatedRunOptions): Promise<void>
Discovers file’s condition tree in its own child, then runs every
executable leaf in a child of its own.
Enclosing scopes are opened here rather than in a child: one such scope spans
several children, so only the parent can own it.
Parameters
sinkReceives every event of every child, in order.
registryResolves each leaf’s measure, whose scheduling constrains
the fork.
runForkUnitInChild(start: Omit<StartMessage, "t" | "runtime">, sink: ISink<{
conditionTitle: string;
kind: "condition-result";
measure: string;
result: unknown;
} | {
arm: "shared" | "isolated";
caseTitle: string;
kind: "case-execution";
measure: string;
replicate: number;
result: unknown;
} | {
caseTitle: string;
kind: "case-result";
measure: string;
result: unknown;
} | {
file: string;
kind: "load-error";
message: string;
} | {
kind: "run-description";
machine: {
architecture: string;
availableParallelism: number;
cpuGovernor: string | null;
cpuModel: string;
kernelRelease: string;
logicalCores: number;
memoryGiB: number;
os: string;
physicalCores: number | null;
};
run: {
argv: string[];
id: string;
mode: string | null;
orderSeed: number;
plan: {
cooldown: boolean;
isolatedRuns: number;
maxReplicates: number;
replicates: number;
retryOnInstability: number;
rounds: number;
};
startedAt: string;
tool: {
name: "@ac-bench/lib";
version: string;
};
};
} | {
kind: "runtime-description";
runtime: {
capabilities: {
allocationCounter: "v8-total-allocated" | "gc-profiler" | "heap-growth" | "browser-heap-growth" | null;
cpuTime: boolean;
forcedCollection: boolean;
};
clock: {
readCostMs: number;
resolutionMs: number;
source: "performance.now";
};
crossOriginIsolated: boolean | null;
device: {
model: string;
os: string;
osVersion: string;
} | null;
engine: "v8" | "spidermonkey" | "javascriptcore";
flags: string[];
headless: boolean | null;
id: string;
isolation: "browser" | "process" | "context" | "reload";
kind: "node" | "browser";
product: string;
userAgent: string | null;
version: string;
};
} | {
gate: {
conditionPath: number[];
declaration: {
denominators: string[];
id?: string;
kind: "ratio";
max?: number;
maxDispersion?: number;
metric?: string;
min?: number;
numerator: string;
rationale?: string;
runtimes?: string[];
} | {
id?: string;
kind: "difference";
max?: number;
maxDispersion?: number;
metric?: string;
min?: number;
rationale?: string;
reference: string;
runtimes?: string[];
subject: string;
} | {
id?: string;
kind: "bound";
max?: number;
maxDispersion?: number;
metric?: string;
min?: number;
rationale?: string;
runtimes?: string[];
subject: string;
};
file: string;
origin: "suite";
} | {
declaration: {
denominators: (string | {
case: string;
condition: ... | ...;
file?: ... | ...;
} | {
case: string;
})[];
id?: string;
kind: "ratio";
max?: number;
maxDispersion?: number;
metric?: string;
min?: number;
numerator: string | {
case: string;
condition: string | ...[];
file?: string;
} | {
case: string;
};
rationale?: string;
runtimes?: string[];
} | {
id?: string;
kind: "difference";
max?: number;
maxDispersion?: number;
metric?: string;
min?: number;
rationale?: string;
reference: string | {
case: string;
condition: string | ...[];
file?: string;
} | {
case: string;
};
runtimes?: string[];
subject: string | {
case: string;
condition: string | ...[];
file?: string;
} | {
case: string;
};
} | {
id?: string;
kind: "bound";
max?: number;
maxDispersion?: number;
metric?: string;
min?: number;
rationale?: string;
runtimes?: string[];
subject: string | {
case: string;
condition: string | ...[];
file?: string;
} | {
case: string;
};
} | {
id?: string;
kind: "baseline";
maxDispersion?: number;
maxRegression?: number;
metric?: string;
normalizeBy?: string | {
case: string;
condition: string | ...[];
file?: string;
} | {
case: string;
};
rationale?: string;
runtimes?: string[];
subjects?: (string | {
case: ...;
condition: ...;
file?: ...;
} | {
case: ...;
})[];
};
origin: "config" | "cli";
};
kind: "gate-declaration";
} | {
kind: "gate-verdict";
verdict: {
adjustedPValue: number | null;
degreesOfFreedom: number | null;
dispersion: number | null;
escalatedReplicates: number;
estimate: number | null;
estimator: "paired" | "unpaired" | "single" | null;
executions: number[];
id: string;
interval: {
level: number;
lower: number;
upper: number;
} | null;
kind: "ratio" | "difference" | "bound" | "baseline";
message: string;
metric: {
direction: "lower-is-better" | "higher-is-better";
name: string;
scale: "log" | "linear";
unit: {
scale: number;
symbol: string;
};
};
origin: "suite" | "config" | "cli";
pValue: number | null;
rationale?: string;
reason: "decided" | "interval-contains-threshold" | "multiplicity" | "dispersion-exceeds-limit" | "too-few-executions" | "no-threshold" | "case-failed" | "case-filtered" | "metric-unavailable" | "non-positive-value" | "runtime-unsupported" | "runtime-unavailable" | "baseline-case-missing" | "baseline-environment-mismatch";
runtime: string;
subjects: {
caseTitle: string;
conditionTitles: string[];
file: string;
runtime: string;
}[];
threshold: {
max?: number;
min?: number;
};
verdict: "error" | "pass" | "fail" | "inconclusive" | "reported" | "skipped" | "not-applicable" | "incomparable";
};
} | {
completedUnits: number;
kind: "run-progress";
totalUnits: number;
} | {
cases: {
selected: boolean;
title: string;
}[];
conditionPath: number[];
file: string;
kind: "unit-declaration";
measure: string;
runtime: string;
titles: string[];
}>, onDiagnostic: (diagnostic: {
attributes?: Record<string, unknown>;
code?: string;
message: string;
severity: "info" | "warning" | "error";
source?: SourceLocation;
}) => void, options?: ForkOptions): Promise<ChildOutcome>
Starts a child, runs one fork unit in it, and replays everything it reports
into sink in order.
The child’s own scopes are closed out here if it dies without saying it was
done, so a crash can never strand a scope.
Parameters
startThe start message; its runtime is the one the child runs in.
saveBaseline(archive: BenchArchive, reference: string, directory?: string): Promise<string>
Files archive as a baseline: under reference as a path, or as a name in
the directory of its own fingerprint.
Returns Where it was written.
toForkOptions(options?: IsolatedRunOptions): ForkOptions
The fork-level subset of options, with the run identity resolved once so
every child of one call shares it.
verdictDiagnostic(verdict: GateVerdict): {
attributes?: Record<string, unknown>;
code?: string;
message: string;
severity: "info" | "warning" | "error";
source?: SourceLocation;
}
A gate verdict as the generic diagnostic sinks read it: error for a fail or
an error, warning for an undecided or incomparable gate, info otherwise.
Its code is gate-<verdict>, so a sink that renders gates itself can leave
these out.
withMeasureScheduling(base: ForkOptions, scheduling: MeasureScheduling): ForkOptions
base with a measure’s declared child requirements merged in: its execArgv
after the run’s, its env over the run’s, its browser launch options.
class BaselineError extends Error
A baseline name or path that does not lead to a readable bench archive.
- new (reference: string, message: string, options?: ErrorOptions): BaselineError
- readonly reference: string
class BenchFileLocationError extends Error
A bench file with no path relative to the run’s working directory — on
another Windows drive or network share — and so no location-independent
identity: a usage error, raised before anything runs.
- new (file: string, cwd: string): BenchFileLocationError
- readonly cwd: string
- readonly file: string
class ChildExitedError extends Error
A child exited before reporting that it was done.
- new (code: number | null, signal: string | null, options?: ErrorOptions & {
readonly reason?: string | null;
}): ChildExitedError
- readonly code: number | null
- readonly reason: string | null
What the runtime says ended the child, when it says more than a code.
- readonly signal: string | null
class ChildTimeoutError extends Error
A child stopped producing messages without having finished.
- new (timeoutMs: number): ChildTimeoutError
- readonly timeoutMs: number
class ConditionTimeoutError extends Error
A fork unit outlived its wall-clock budget.
- new (timeoutMs: number): ConditionTimeoutError
- readonly timeoutMs: number
class CooldownGate
Waits between fork units until the machine stops recovering, never inside a
timed case.
Waiting is preventive where retrying is corrective: it avoids paying for a
bad measurement rather than noticing one afterwards. The stopping rule is the
derivative, not the baseline — ambient conditions may simply have changed,
so waiting for the exact starting temperature would never terminate.
- new (probe: EnvironmentProbe, baseline: EnvironmentBaseline, options?: CooldownOptions): CooldownGate
- get totalCooldownMs(): number
Time already spent cooling across every gate so far.
- settle(signal?: AbortSignal): Promise<CooldownResult>
class EnvironmentMonitor
Samples the machine while a child measures, and judges what it saw.
The parent is idle during a measurement, which makes it the only process in a
position to watch the things a fork cannot isolate.
- new (probe: EnvironmentProbe, options?: EnvironmentMonitorOptions): EnvironmentMonitor
- start(): void
- stop(): Promise<EnvironmentVerdict>
Stops sampling and classifies everything collected since start().
class IpcReportReceiver
Turns one child’s message stream into sink writes, asserting the sequence,
renewing the child’s credit, and remembering which scopes it left open so a
crash can still be closed out.
- new (input: IpcReportReceiverInput): IpcReportReceiver
- fatal: unknown
The error the child reported as fatal, if any.
- status: "skipped" | "ok" | "failed" | "cancelled" | null
The status the child reported, or null while it is still running.
- get deepestOpenScope(): string | null
The innermost scope the child has open, for attributing its output.
- get openScopes(): readonly string[]
Scopes the child opened and never closed, deepest last.
- closeOpenScopes(error: unknown): Promise<void>
Writes a synthetic scope-end for everything the child left open, so a
crash cannot strand a scope. Innermost first.
- receive(raw: unknown): Promise<void>
class SequenceGapError extends Error
The child’s seq did not follow the previous one.
- new (expected: number, received: number): SequenceGapError
- readonly expected: number
- readonly received: number
const DEFAULT_HEARTBEAT_TIMEOUT_MS: 30000
No message from a child for this long means it is no longer making progress.
const DEFAULT_OUTPUT_BASE_NAME: "bench-results"
Base name for output files when nobody names one.
const NODE_RUNTIME_ID: "node"
The id of the runtime every run measures in unless another is selected. Its
conditions keep keys without a runtime prefix, so a Node-only run keys its
scopes as it always has.
interface BenchChild extends AsyncDisposable
One measuring (or discovering) context: a Node process, a browser page.
- readonly label: string
For logs: "pid 4242", "chromium page 3".
- readonly pid: number | undefined
The OS process the monitor should watch, when there is one on this host.
- onMessage(listener: Callable<[message: unknown]>): CallableNoArgs
Every message the child sends, in order, from the moment it is called.
Returns Unsubscribes.
- onOutput(listener: Callable<[stream: "stdout" | "stderr", line: string]>): CallableNoArgs
Returns Unsubscribes.
- send(message: {
arm: "shared" | "isolated";
caseFilter?: string[];
conditionPath: number[];
conditionTitles: string[];
emitSamples: boolean;
file: string;
fileLabel: string;
hashSeed?: number;
measureOptions?: Record<string, unknown>;
orderSeed: number;
parentScopeId: string | null;
profile?: boolean;
replicate: number;
rounds: number;
runtime: {
id: string;
kind: "node" | "browser";
};
t: "start";
} | {
artifactCacheRoot: string;
runId: string;
setupFiles?: string[];
t: "hello";
version: number;
} | {
file: string;
t: "list";
} | {
seq: number;
t: "ack";
} | {
reason: string;
t: "abort";
}): Promise<void>
Resolves once the child side accepted the message.
- terminate(): Promise<void>
Ask, then force: SIGTERM then SIGKILL, or close the page then the browser.
- waitForExit(): Promise<ChildExit>
Resolves once the child is gone, however it went. Never rejects.
interface ExecutionRuntime extends AsyncDisposable
Where bench files run: everything a run needs to start a child, exchange
protocol messages with it and notice it died. Discovery, the measurement
plan, pooling and reporting are the same whatever the runtime.
- readonly environmentProbe?: EnvironmentProbe
Host- or device-side probe for the environment monitor and cooldown.
Absent: the host’s own.
- readonly id: string
- readonly kind: "node" | "browser"
- describe(): Omit<RuntimeDescription, "clock" | "crossOriginIsolated" | "userAgent" | "capabilities">
The launch-side half of the description; a child’s hello completes it.
- prepare(files: readonly string[], signal: AbortSignal): Promise<void>
Called once per run with every selected file: bundling, servers, devices.
- spawn(request: ChildSpawnRequest): Promise<BenchChild>
type BenchRunOptions = unknown
How a run is carried out, already resolved.
Nothing here is an intent: naming one (--mode rigorous, a reporter id, a
glob) and turning it into these values is configuration, and belongs to
whoever parses it.
type BenchRunOutcome = unknown
type ChildExit = unknown
type ChildOutcome = unknown
type ChildSpawnRequest = unknown
What a child is spawned for, and with what.
type CooldownOptions = unknown
type CooldownResult = unknown
type EnvironmentBaseline = unknown
What the machine looked like before any measurement ran.
type EnvironmentMonitorOptions = unknown
type EnvironmentProbe = () => Promise<EnvironmentSample>
type EnvironmentSample = unknown
One observation of everything a child process does not isolate.
type EnvironmentStability = "stable" | "drifting" | "unstable"
type EnvironmentVerdict = unknown
type ForkOptions = unknown
type ForkUnitIdentity = unknown
Where a fork unit sits, as keys and gates name it.
type IpcReportReceiverInput = unknown
type IpcReportReceiverOptions = unknown
type IsolatedRunOptions = unknown
type MeasurementPlan = z.infer<typeof measurementPlanSchema>
type NodeEnvironmentProbeOptions = unknown
type NodeRuntimeOptions = unknown
type ProfileRequest = unknown
Which case to profile: its titles, and where several files declare it.
type ReporterContextOptions = unknown
type RuntimeContext = unknown
What a runtime plugin is handed to create its runtime.
type RuntimeDiagnosis = unknown
One runtime’s doctor report.
type RuntimePlugin = BrandedRuntimePlugin & {
create(context: RuntimeContext): Promise<ExecutionRuntime>;
diagnose(context: RuntimeContext): Promise<RuntimeDiagnosis>;
}
A runtime a config lists in plugins and selects by id in runtimes: the
reporter pattern, where listing configures and selecting runs.
type RuntimeProblem = unknown
Something that keeps a runtime from running, and what fixes it.