@yaks/benchmark 0.0.0-stage → 0.2.36

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.
@@ -0,0 +1,27 @@
1
+ /** Timed sync or async workloads. Setup and teardown are outside each sample;
2
+ * operations normalizes a batch, while iterations keeps individual samples. */ import type { Bench, Workload } from "./result.js";
3
+ type DurationUnit = 'ns' | 'us' | 'ms' | 's';
4
+ export type TimeUnit = DurationUnit | `${DurationUnit}/${string}`;
5
+ export type Iteration = {
6
+ round: number;
7
+ iteration: number;
8
+ };
9
+ export type TimedBench = Pick<Workload, 'name' | 'resolution'> & {
10
+ unit: TimeUnit;
11
+ run: (iteration: Iteration) => unknown;
12
+ /** How many independent timed invocations to keep in each round. */ iterations?: number;
13
+ /** How many operations one invocation performs. */ operations?: number;
14
+ setup?: (iteration: Iteration) => unknown;
15
+ teardown?: (iteration: Iteration) => unknown;
16
+ /** Record this target's work (for example, a graph). Without a target, the
17
+ * tree contains the bench invocation's own span. */ target?: object;
18
+ };
19
+ /** Start timing a step; the function it returns says how long it took since,
20
+ * in ms: its wall time and CPU time (host.ts
21
+ * `cputime`). An externally measured bench spreads the reading into its
22
+ * sample, `{ ...took(), source }`. */ export declare let stopwatch: (...sources: (() => number)[]) => () => {
23
+ value: number;
24
+ cpu: number;
25
+ };
26
+ export declare let bench: (options: TimedBench) => Bench;
27
+ //# sourceMappingURL=bench.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bench.d.ts","sources":["../bench.ts"],"names":[],"mappings":"AAAA;6EAC6E,GAC7E,cAAc,KAAK,EAAU,QAAQ,sBAAqB;KAIrD,eAAe,OAAO,OAAO,OAAO;AACzC,YAAY,WAAW,kBAAkB,aAAa,CAAC,EAAE,MAAM;AAC/D,YAAY;EAAc,OAAO,MAAM;EAAE,WAAW,MAAM;;AAC1D,YAAY,aAAa,KAAK,UAAU,SAAS;EAC/C,MAAM;EACN,MAAM,WAAW,cAAc,OAAO;EACtC,kEAAkE,GAClE,aAAa,MAAM;EACnB,iDAAiD,GACjD,aAAa,MAAM;EACnB,SAAS,WAAW,cAAc,OAAO;EACzC,YAAY,WAAW,cAAc,OAAO;EAC5C;oDACkD,GAClD,SAAS,MAAM;;AAGjB;;;oCAGoC,GACpC,OAAO,YAAI,YACT,GAAG,gBAAgB,MAAM;EAChB,OAAO,MAAM;EAAE,KAAK,MAAM;EAIpC;AAED,OAAO,YAAI,QAAS,SAAS,eAAa,MAmEzC"}
@@ -0,0 +1,21 @@
1
+ /** Import CPU invocation averages from the shared Deno workload collector.
2
+ * Keep wall time and collector statistics alongside the CPU measurement. */ import { type Sample, type Sampling } from "./result.js";
3
+ export type DenoReport = {
4
+ version: number;
5
+ runtime: string;
6
+ cpu: string;
7
+ benches: {
8
+ name: string;
9
+ results: {
10
+ ok?: {
11
+ avg: number;
12
+ cpu?: number;
13
+ sampling?: Sampling;
14
+ [key: string]: unknown;
15
+ };
16
+ failed?: unknown;
17
+ }[];
18
+ }[];
19
+ };
20
+ export declare let extract: (report: DenoReport, expected: readonly string[]) => Record<string, Sample>;
21
+ //# sourceMappingURL=deno.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deno.d.ts","sources":["../deno.ts"],"names":[],"mappings":"AAAA;0EAC0E,GAC1E,SAAoB,KAAK,MAAM,EAAE,KAAK,QAAQ,sBAAqB;AAEnE,YAAY;EACV,SAAS,MAAM;EACf,SAAS,MAAM;EACf,KAAK,MAAM;EACX;IACE,MAAM,MAAM;IACZ;MACE;QACE,KAAK,MAAM;QACX,MAAM,MAAM;QACZ,WAAW;SACV,KAAK,MAAM,GAAG,OAAO;;MAExB,SAAS,OAAO;;;;AAItB,OAAO,YAAI,UACT,QAAQ,YACR,mBAAmB,MAAM,OACxB,OAAO,MAAM,EAAE,QAyBjB"}
@@ -0,0 +1,42 @@
1
+ /** The process boundary: host config and machine metadata are read for each
2
+ * run, not when a bench is declared. Reporter factories receive this context;
3
+ * the default factory is empty until a reporting provider is installed. */ import type { Run } from "./result.js";
4
+ export type Host = {
5
+ config: Record<string, unknown>;
6
+ /** Config-relative provider paths are resolved against this URL. */ configURL: string | null;
7
+ commit: string | null;
8
+ runtime: string;
9
+ cpu: string;
10
+ load: readonly number[];
11
+ /** The share of the box's CPUs in use over a second the bench rests; absent
12
+ * or undefined where the box does not say. The runner samples it before
13
+ * each round (`Run.busy`). */ busy?: () => Promise<number | undefined>;
14
+ };
15
+ type Immutable<T> = T extends object ? {
16
+ readonly [K in keyof T]: Immutable<T[K]>;
17
+ } : T;
18
+ export type ReportedRun = Immutable<Run>;
19
+ export type Reporter = (run: ReportedRun) => void | Promise<void>;
20
+ export type Reporters = (host: Host) => readonly Reporter[] | Promise<readonly Reporter[]>;
21
+ /** Install the process's reporter factory. It reads the current host config
22
+ * on every run; workload modules neither configure nor construct reporters. */ export declare let configure: (factory: Reporters) => () => void;
23
+ export declare let host: () => Promise<Host>;
24
+ /** The share of the box's CPUs in use over the next `ms` while the caller
25
+ * waits: the other work on the box. It is use, not CPU pressure, because a
26
+ * busy hyperthread slows the work on its sibling without making anything wait
27
+ * for a CPU: two of four busy cost a CPU-bound bench about a tenth. */ export declare let busy: (ms?: number) => Promise<number | undefined>;
28
+ /** CPU milliseconds used by every thread in this process and its finished,
29
+ * waited-for children, user and system, from getrusage(2) on Linux and Darwin.
30
+ * Other platforms fail explicitly: self-only CPU would miss child work.
31
+ * A child counts after it exits and is reaped; a process that outlives a
32
+ * measurement must report its CPU separately. */ export declare let cputime: () => number;
33
+ /** CPU milliseconds used by the calling thread and this process's finished,
34
+ * waited-for children, user and system: `cputime` without the process's other
35
+ * threads, where V8 compiles, collects garbage and runs blocking I/O beside
36
+ * the thread whenever it likes. Two readings bracket the thread's own work. */ export declare let threadtime: () => number;
37
+ /** How long the calling thread has waited for a CPU since it started, in ms:
38
+ * the time other work took from it, as Linux keeps it (schedstat's run delay);
39
+ * undefined where the platform does not say. Two readings bracket what load
40
+ * added to a span of the thread's work, so wall time less their difference is
41
+ * what the span would have taken on an idle box. */ export declare let waited: () => number | undefined;
42
+ //# sourceMappingURL=host.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host.d.ts","sources":["../host.ts"],"names":[],"mappings":"AAGA;;yEAEyE,GACzE,cAAc,GAAG,sBAAqB;AAGtC,YAAY;EACV,QAAQ,OAAO,MAAM,EAAE,OAAO;EAC9B,kEAAkE,GAClE,WAAW,MAAM,GAAG,IAAI;EACxB,QAAQ,MAAM,GAAG,IAAI;EACrB,SAAS,MAAM;EACf,KAAK,MAAM;EACX,eAAe,MAAM;EACrB;;8BAE4B,GAC5B,aAAa,QAAQ,MAAM,GAAG,SAAS;;KAEpC,UAAU,KAAK,UAAU,MAAM;YACpB,WAAW,IAAI,UAAU,EAAE;IACvC;AACJ,YAAY,cAAc,UAAU;AACpC,YAAY,YAAY,KAAK,gBAAgB,IAAI,GAAG,QAAQ,IAAI;AAChE,YAAY,aACV,MAAM,kBACM,aAAa,iBAAiB;AAG5C;6EAC6E,GAC7E,OAAO,YAAI,YAAa,SAAS,oBAAkB,IAAI,CAMtD;AAGD,OAAO,YAAI,YAAiB,QAAQ,MAuCnC;AAcD;;;qEAGqE,GACrE,OAAO,YAAI,OAAc,gBAAY,QAAQ,MAAM,GAAG,SAAS,EAO9D;AAqCD;;;;+CAI+C,GAC/C,OAAO,YAAI,eAAc,MAAM,CAG9B;AAED;;;6EAG6E,GAC7E,OAAO,YAAI,kBAAiB,MAAM,CAGjC;AAED;;;;kDAIkD,GAClD,OAAO,YAAI,cAAa,MAAM,GAAG,SAAS,CAQzC"}
package/_dist/mod.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ /** Named workloads and their measurements, with a pure ratchet and a JSON
2
+ * runner. Benches know their work and unit; the process owns reporting. */ export { bench, type Iteration, stopwatch, type TimedBench, type TimeUnit } from "./bench.js";
3
+ export { type Baseline, type Bench, type CollectedSuite, type Direction, insufficient, median, type Regression, type Result, type Round, type Run, type Sample, type Samples, type Sampling, type Suite, type Workload } from "./result.js";
4
+ export { baseline, best, compare, type Coverage, incomparable, limit, loaded, spread } from "./ratchet.js";
5
+ export { busy, configure, cputime, type Host, host, type ReportedRun, type Reporter, type Reporters, threadtime, waited } from "./host.js";
6
+ export { type Files, type Options, Regressed, run } from "./runner.js";
7
+ export { processCpu } from "./process.js";
8
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sources":["../mod.ts"],"names":[],"mappings":"AAAA;yEACyE,GACzE,SACE,KAAK,EACL,KAAK,SAAS,EACd,SAAS,EACT,KAAK,UAAU,EACf,KAAK,QAAQ,qBACI;AACnB,SACE,KAAK,QAAQ,EACb,KAAK,KAAK,EACV,KAAK,cAAc,EACnB,KAAK,SAAS,EACd,YAAY,EACZ,MAAM,EACN,KAAK,UAAU,EACf,KAAK,MAAM,EACX,KAAK,KAAK,EACV,KAAK,GAAG,EACR,KAAK,MAAM,EACX,KAAK,OAAO,EACZ,KAAK,QAAQ,EACb,KAAK,KAAK,EACV,KAAK,QAAQ,sBACK;AACpB,SACE,QAAQ,EACR,IAAI,EACJ,OAAO,EACP,KAAK,QAAQ,EACb,YAAY,EACZ,KAAK,EACL,MAAM,EACN,MAAM,uBACa;AACrB,SACE,IAAI,EACJ,SAAS,EACT,OAAO,EACP,KAAK,IAAI,EACT,IAAI,EACJ,KAAK,WAAW,EAChB,KAAK,QAAQ,EACb,KAAK,SAAS,EACd,UAAU,EACV,MAAM,oBACU;AAClB,SAAS,KAAK,KAAK,EAAE,KAAK,OAAO,EAAE,SAAS,EAAE,GAAG,sBAAqB;AAEtE,SAAS,UAAU,uBAAsB"}
@@ -0,0 +1,2 @@
1
+ export declare let processCpu: (pid: number) => number;
2
+ //# sourceMappingURL=process.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process.d.ts","sources":["../process.ts"],"names":[],"mappings":"AAYA,OAAO,YAAI,aAAc,KAAK,MAAM,KAAG,MAAM,CAoC5C"}
@@ -0,0 +1,64 @@
1
+ /** The pure ratchet compares compatible suite measurements. A baseline is a
2
+ * value with its own slack; accepting it is an explicit runner operation.
3
+ * A figure counts only where it clears the noise. A regression is a figure
4
+ * past its reference by more than the noise of both measurements; a baseline
5
+ * moves toward better only by as much, and never on a run the box measured
6
+ * while loaded. Banking worse numbers is a separate, explicit choice
7
+ * (`slower`, for the whole suite or the benches it names), never what an
8
+ * ordinary acceptance does. */ import { type Baseline, type Direction, type Regression, type Run } from "./result.js";
9
+ /** Whether the box was loaded while a run measured. A loaded run confirms no
10
+ * regression and banks no baseline: its figures carry the other work. */ export declare let loaded: (run: Pick<Run, 'busy'>) => boolean;
11
+ /** How far apart repeated medians of one bench fall, as a fraction of the
12
+ * best of them: the noise a figure carries, which a check has to allow.
13
+ *
14
+ * ```ts
15
+ * import { spread } from '@yaks/benchmark'
16
+ * import { equal } from '@yaks/testing'
17
+ *
18
+ * equal(spread([100, 104, 110], 'lower'), .1)
19
+ * equal(spread([80, 100], 'higher'), .2)
20
+ * equal(spread([5], 'lower'), 0)
21
+ * ```
22
+ */ export declare let spread: (medians: readonly number[], better: Direction) => number;
23
+ /** Repeated runs of one suite as one run: each bench as the run that measured
24
+ * it best, the median acceptance banks, so a check compares like for like,
25
+ * with the spread of every round median the runs took between them, and the
26
+ * busiest box any of them saw.
27
+ *
28
+ * ```ts
29
+ * import { best, type Run } from '@yaks/benchmark'
30
+ * import { equal } from '@yaks/testing'
31
+ *
32
+ * let run = (write: number, rate: number) => ({
33
+ * benches: [
34
+ * { name: 'write', better: 'lower', rounds: [{ median: write }] },
35
+ * { name: 'rate', better: 'higher', rounds: [{ median: rate }] },
36
+ * ].map((b) => ({ ...b, median: b.rounds[0].median })),
37
+ * }) as Run
38
+ * let one = best([run(12, 40), run(10, 30)])
39
+ * equal(one.benches.map((b) => b.median), [10, 40])
40
+ * equal(one.benches.map((b) => b.spread), [.2, .25])
41
+ * ```
42
+ */ export declare let best: (runs: readonly Run[]) => Run;
43
+ declare let KEYS: readonly ['version', 'suite', 'metric', 'workload', 'runtime', 'cpu'];
44
+ type Key = typeof KEYS[number];
45
+ /** The first piece of metadata that keeps a run from comparing with a
46
+ * baseline, or undefined when the two compare. */ export declare let incomparable: (base: Pick<Baseline, Key>, current: Pick<Run, Key>) => Key | undefined;
47
+ /** Bank one run, or several repeated runs of one suite, as a baseline. Each
48
+ * bench banks its best median and, as its slack, NOISE times the spread of
49
+ * its round medians, never under `allowed` and never over CAP. Against a
50
+ * previous baseline a bench moves only when its new median clears the noise
51
+ * of both, that is when the banked median would have regressed against it;
52
+ * otherwise it keeps its median and the wider slack. `slower` banks the
53
+ * measurement as it is, worse or not: every bench's, or only the named ones',
54
+ * leaving every other bench as it was banked. A run the box measured while
55
+ * loaded
56
+ * never banks, and a scoped acceptance retains the workloads it did not
57
+ * measure. */ export declare let baseline: (current: Run | readonly Run[], allowed: number, previous?: Baseline, slower?: boolean | readonly string[]) => Baseline;
58
+ export type Coverage = 'exact' | 'subset';
59
+ /** The figure a banked bench may reach before it has regressed: its median
60
+ * moved by its own slack, else the baseline's, or by NOISE times the `spread`
61
+ * the check itself measured where that is wider, so a figure must clear the
62
+ * noise of both measurements. Rounded to its resolution. */ export declare let limit: (base: Baseline, b: Baseline['benches'][number], spread?: number) => number;
63
+ export declare let compare: (base: Baseline, current: Run, coverage?: Coverage) => Regression[];
64
+ //# sourceMappingURL=ratchet.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ratchet.d.ts","sources":["../ratchet.ts"],"names":[],"mappings":"AAAA;;;;;;;6BAO6B,GAC7B,SACE,KAAK,QAAQ,EACb,KAAK,SAAS,EAEd,KAAK,UAAU,EACf,KAAK,GAAG,sBAIU;AAqBpB;uEACuE,GACvE,OAAO,YAAI,SAAU,KAAK,KAAK,KAAK,YAAU,OAAO,CAA0B;AAa/E;;;;;;;;;;;CAWC,GACD,OAAO,YAAI,SAAU,kBAAkB,MAAM,IAAI,QAAQ,cAAY,MAAM,CAI1E;AAED;;;;;;;;;;;;;;;;;;;CAmBC,GACD,OAAO,YAAI,OAAQ,eAAe,UAAQ,IAoBzC;AAwBD,YAAI,gBAAQ,WAAW,SAAS,UAAU,YAAY,WAAW;KAC5D,aAAa,KAAK,MAAM;AAC7B;gDACgD,GAChD,OAAO,YAAI,eACT,MAAM,KAAK,UAAU,MACrB,SAAS,KAAK,KAAK,SAClB,MAAM,SAAS,CAAkD;AAgBpE;;;;;;;;;;YAUY,GACZ,OAAO,YAAI,WACT,SAAS,eAAe,OACxB,SAAS,MAAM,EACf,WAAW,UACX,SAAQ,OAAO,YAAY,MAAM,OAChC,SAgFF;AAcD,YAAY,WAAW,UAAU;AAMjC;;;0DAG0D,GAC1D,OAAO,YAAI,QACT,MAAM,UACN,GAAG,SAAS,WAAW,MAAM,GAC7B,oBACC,MAAM,CAOR;AACD,OAAO,YAAI,UACT,MAAM,UACN,SAAS,KACT,WAAU,aACT,aA8CF"}
@@ -0,0 +1,103 @@
1
+ /** The data shared by bench authors, the runner, the ratchet and reporters.
2
+ * Samples keep their round and provenance; a Deno average is never described
3
+ * as an individual operation's timing. No effect belongs in this module. */ import type { Event } from "@yaks/trace";
4
+ /** The collector kept the CPU reading but could not sample enough timed work.
5
+ * Durations are total CPU milliseconds, before per-operation normalization. */ export type Sampling = {
6
+ status: 'insufficient';
7
+ minimum: number;
8
+ measured: number;
9
+ outer: number;
10
+ };
11
+ export type Sample = {
12
+ value: number;
13
+ /** The CPU time the step took, in the bench's unit: this process's and its
14
+ * finished children's (host.ts `cputime`). Absent where the step's work runs
15
+ * in a process that outlives it, or where the box does not say. */ cpu?: number;
16
+ sampling?: Sampling;
17
+ counts?: Record<string, number>;
18
+ source?: string;
19
+ details?: unknown;
20
+ spans?: readonly Event[];
21
+ };
22
+ export type Samples = number | Sample | readonly Sample[];
23
+ export type Direction = 'lower' | 'higher';
24
+ export type Workload = {
25
+ name: string;
26
+ unit: string;
27
+ better?: Direction;
28
+ /** Precision in this workload's unit, used to round the tolerance boundary. */ resolution?: number;
29
+ };
30
+ export type Bench = Workload & {
31
+ sample: (round: number) => Samples | Promise<Samples>;
32
+ };
33
+ export type Suite = {
34
+ name: string;
35
+ /** The aggregation contract, compared verbatim by the ratchet. */ metric: string;
36
+ /** Change this when the corpus or timed boundary changes. */ workload: string | number;
37
+ benches: readonly Bench[];
38
+ /** Release collection resources after the final round, including failures. */ close?: () => void | Promise<void>;
39
+ };
40
+ /** A shared collector can measure several workloads in one external process. */ export type CollectedSuite = Omit<Suite, 'benches'> & {
41
+ benches: readonly Workload[];
42
+ collect: (round: number) => Record<string, Samples> | Promise<Record<string, Samples>>;
43
+ };
44
+ export type Round = {
45
+ index: number;
46
+ median: number;
47
+ /** The median of its samples' CPU time, where every sample has one. */ cpu?: number;
48
+ /** Reserved for the recorded span tree, rather than live channel history. */ spans: readonly Event[] | null;
49
+ };
50
+ export type Result = Workload & {
51
+ better: Direction;
52
+ samples: (Sample & {
53
+ round: number;
54
+ })[];
55
+ rounds: Round[];
56
+ median: number;
57
+ /** How far apart its round medians fell, across every run of the
58
+ * measurement, as a fraction of the best (ratchet.ts `spread`): the noise
59
+ * this figure carries. */ spread: number;
60
+ /** The median round's recorded span tree. */ spans: readonly Event[] | null;
61
+ };
62
+ export type Regression = {
63
+ reference?: string;
64
+ name: string;
65
+ unit: string;
66
+ baseline: number;
67
+ /** The figure the bench was allowed to reach: its baseline and slack. */ limit: number;
68
+ current: number;
69
+ /** A positive fraction is worse, for either direction. */ change: number | null;
70
+ };
71
+ export type Run = {
72
+ version: 1;
73
+ suite: string;
74
+ metric: string;
75
+ workload: string | number;
76
+ at: string;
77
+ commit: string | null;
78
+ runtime: string;
79
+ cpu: string;
80
+ /** The box's one, five and fifteen minute load averages as the run began. */ load: readonly number[];
81
+ /** The most of the box's CPUs other work used in the second before a
82
+ * round, while the bench rested (host.ts `busy`), or null where the box
83
+ * does not say. Over BUSY, the run is loaded (ratchet.ts `loaded`). */ busy: number | null;
84
+ rounds: number;
85
+ benches: Result[];
86
+ tolerance: number | null;
87
+ /** `loaded`: a figure was past its limit on a loaded box.
88
+ * `inconclusive`: CPU sampling was insufficient; readings remain diagnostic. */ verdict: 'measured' | 'passed' | 'regressed' | 'loaded' | 'accepted' | 'inconclusive';
89
+ regressions: Regression[];
90
+ };
91
+ export type Baseline = Pick<Run, 'version' | 'suite' | 'metric' | 'workload' | 'runtime' | 'cpu'> & {
92
+ /** The revision measured when converting a baseline to a new metric. */ reference?: string;
93
+ /** The slack a bench without its own may take. */ tolerance: number;
94
+ benches: (Workload & {
95
+ better: Direction;
96
+ /** The product revision this individual workload was banked against. */ reference?: string;
97
+ median: number;
98
+ /** The slack this bench measured for itself when it was banked. */ tolerance?: number;
99
+ })[];
100
+ };
101
+ /** Insufficient sampling is an observation, never a pass or a regression. */ export declare let insufficient: (run: Pick<Run, 'benches'> & Partial<Pick<Run, 'verdict'>>) => boolean;
102
+ export declare let median: (values: readonly number[]) => number;
103
+ //# sourceMappingURL=result.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"result.d.ts","sources":["../result.ts"],"names":[],"mappings":"AAAA;;0EAE0E,GAE1E,cAAc,KAAK,2BAAgC;AAEnD;6EAC6E,GAC7E,YAAY;EACV,QAAQ;EACR,SAAS,MAAM;EACf,UAAU,MAAM;EAChB,OAAO,MAAM;;AAGf,YAAY;EACV,OAAO,MAAM;EACb;;mEAEiE,GACjE,MAAM,MAAM;EACZ,WAAW;EACX,SAAS,OAAO,MAAM,EAAE,MAAM;EAC9B,SAAS,MAAM;EACf,UAAU,OAAO;EACjB,iBAAiB;;AAEnB,YAAY,UAAU,MAAM,GAAG,kBAAkB;AACjD,YAAY,YAAY,UAAU;AAClC,YAAY;EACV,MAAM,MAAM;EACZ,MAAM,MAAM;EACZ,SAAS;EACT,6EAA6E,GAC7E,aAAa,MAAM;;AAErB,YAAY,QAAQ;EAClB,SAAS,OAAO,MAAM,KAAK,UAAU,QAAQ;;AAE/C,YAAY;EACV,MAAM,MAAM;EACZ,gEAAgE,GAChE,QAAQ,MAAM;EACd,2DAA2D,GAC3D,UAAU,MAAM,GAAG,MAAM;EACzB,kBAAkB;EAClB,4EAA4E,GAC5E,cAAc,IAAI,GAAG,QAAQ,IAAI;;AAEnC,8EAA8E,GAC9E,YAAY,iBAAiB,KAAK,OAAO;EACvC,kBAAkB;EAClB,UAAU,OAAO,MAAM,KACnB,OAAO,MAAM,EAAE,WACf,QAAQ,OAAO,MAAM,EAAE;;AAE7B,YAAY;EACV,OAAO,MAAM;EACb,QAAQ,MAAM;EACd,qEAAqE,GACrE,MAAM,MAAM;EACZ,2EAA2E,GAC3E,gBAAgB,UAAU,IAAI;;AAEhC,YAAY,SAAS;EACnB,QAAQ;EACR,UAAU;IAAW,OAAO,MAAM;;EAClC,QAAQ;EACR,QAAQ,MAAM;EACd;;0BAEwB,GACxB,QAAQ,MAAM;EACd,2CAA2C,GAC3C,gBAAgB,UAAU,IAAI;;AAEhC,YAAY;EACV,YAAY,MAAM;EAClB,MAAM,MAAM;EACZ,MAAM,MAAM;EACZ,UAAU,MAAM;EAChB,uEAAuE,GACvE,OAAO,MAAM;EACb,SAAS,MAAM;EACf,wDAAwD,GACxD,QAAQ,MAAM,GAAG,IAAI;;AAEvB,YAAY;EACV,SAAS;EACT,OAAO,MAAM;EACb,QAAQ,MAAM;EACd,UAAU,MAAM,GAAG,MAAM;EACzB,IAAI,MAAM;EACV,QAAQ,MAAM,GAAG,IAAI;EACrB,SAAS,MAAM;EACf,KAAK,MAAM;EACX,2EAA2E,GAC3E,eAAe,MAAM;EACrB;;uEAEqE,GACrE,MAAM,MAAM,GAAG,IAAI;EACnB,QAAQ,MAAM;EACd,SAAS;EACT,WAAW,MAAM,GAAG,IAAI;EACxB;gFAC8E,GAC9E,SACI,aACA,WACA,cACA,WACA,aACA;EACJ,aAAa;;AAEf,YAAY,WACR,KAAK,KAAK,YAAY,UAAU,WAAW,aAAa,YAAY;EAEpE,sEAAsE,GACtE,YAAY,MAAM;EAClB,gDAAgD,GAChD,WAAW,MAAM;EACjB,UAAU;IACR,QAAQ;IACR,sEAAsE,GACtE,YAAY,MAAM;IAClB,QAAQ,MAAM;IACd,iEAAiE,GACjE,YAAY,MAAM;;;AAIxB,2EAA2E,GAC3E,OAAO,YAAI,eACT,KAAK,KAAK,KAAK,aAAa,QAAQ,KAAK,KAAK,gBAC7C,OAAO,CAIP;AAiBH,OAAO,YAAI,SAAU,iBAAiB,MAAM,OAAK,MAAM,CAOtD"}
@@ -0,0 +1,45 @@
1
+ import * as io from "@yaks/file/io";
2
+ /** Run workloads sequentially, persist JSON before reporting, and accept one
3
+ * suite's baseline only on request. External collectors use the same ratchet
4
+ * and reporting path as timed callbacks. */ import { type Host, type Reporters } from "./host.js";
5
+ import { type CollectedSuite, type Run, type Suite } from "./result.js";
6
+ import { type Coverage } from "./ratchet.js";
7
+ export type Files = {
8
+ read: (path: string) => Promise<string>;
9
+ write: (path: string, value: unknown) => Promise<void>;
10
+ };
11
+ export type Options = {
12
+ rounds?: number;
13
+ /** Judge CPU time; wall readings remain in raw samples for diagnostics. */ figure?: 'cpu';
14
+ mode?: 'run' | 'check' | 'accept';
15
+ output: string;
16
+ baseline?: string;
17
+ /** Where a check keeps this box's own baseline while `baseline` was banked
18
+ * on another runtime or CPU. The first such check banks its run there, and
19
+ * later checks on this runtime and CPU compare with it. */ local?: string;
20
+ /** Required for acceptance: the least slack any bench is banked with.
21
+ * Checks use the baseline's own. */ tolerance?: number;
22
+ /** Measure the suite this many times over, keeping each bench's best median
23
+ * and the spread of every round between them (ratchet.ts `best`).
24
+ * Acceptance banks it with the slack that spread asks for (ratchet.ts
25
+ * `baseline`), and a check compares it, allowing that spread as well, so a
26
+ * check taken as its baseline was banked measures what it banked. */ runs?: number;
27
+ /** Bank the measurement as it is, even a worse median than the baseline's:
28
+ * every bench's, or only the named benches'. Without it acceptance only
29
+ * moves a bench toward better, by more than the noise. */ slower?: boolean | readonly string[];
30
+ host?: () => Host | Promise<Host>;
31
+ reporters?: Reporters;
32
+ files?: Files;
33
+ /** A box-wide flock, held for each round and publication, so queued suites
34
+ * can measure between rounds. Compatible with shell flock; never unlink it. */ lock?: string;
35
+ open?: typeof io.open;
36
+ /** Scoped observations may measure only part of a suite, including new work.
37
+ * Unbanked measurements are reported as measured; acceptance retains the
38
+ * other workloads in the suite's baseline. Exact coverage is the default. */ coverage?: Coverage;
39
+ };
40
+ export declare class Regressed extends Error {
41
+ result: Run;
42
+ constructor(result: Run);
43
+ }
44
+ export declare let run: (suite: Suite | CollectedSuite, options: Options) => Promise<Run>;
45
+ //# sourceMappingURL=runner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runner.d.ts","sources":["../runner.ts"],"names":[],"mappings":"AAAA,YAAY,6BAAkC;AAE9C;;0CAE0C,GAC1C,SAAS,KAAK,IAAI,EAAQ,KAAK,SAAS,oBAA8B;AAEtE,SAEE,KAAK,cAAc,EAKnB,KAAK,GAAG,EAGR,KAAK,KAAK,sBAEQ;AACpB,SAIE,KAAK,QAAQ,uBAQM;AAErB,YAAY;EACV,OAAO,MAAM,MAAM,KAAK,QAAQ,MAAM;EACtC,QAAQ,MAAM,MAAM,EAAE,OAAO,OAAO,KAAK,QAAQ,IAAI;;AAuBvD,YAAY;EACV,SAAS,MAAM;EACf,yEAAyE,GACzE,SAAS;EACT,OAAO,QAAQ,UAAU;EACzB,QAAQ,MAAM;EACd,WAAW,MAAM;EACjB;;2DAEyD,GACzD,QAAQ,MAAM;EACd;oCACkC,GAClC,YAAY,MAAM;EAClB;;;;qEAImE,GACnE,OAAO,MAAM;EACb;;0DAEwD,GACxD,SAAS,OAAO,YAAY,MAAM;EAClC,aAAa,OAAO,QAAQ;EAC5B,YAAY;EACZ,QAAQ;EACR;+EAC6E,GAC7E,OAAO,MAAM;EACb,cAAc,GAAG;EACjB;;6EAE2E,GAC3E,WAAW;;AAEb,OAAO,cAAM,kBAAkB;EACV,QAAQ;EAA3B,YAAY,AAAO,QAAQ,GAAG;AAIhC;AAEA,OAAO,YAAI,MACT,OAAO,QAAQ,gBACf,SAAS,YACR,QAAQ,KAsBV"}
package/bench.js ADDED
@@ -0,0 +1,89 @@
1
+ /** Timed sync or async workloads. Setup and teardown are outside each sample;
2
+ * operations normalizes a batch, while iterations keeps individual samples. */ import * as trace from "@yaks/trace";
3
+ import { cputime } from "./host.js";
4
+ /** Start timing a step; the function it returns says how long it took since,
5
+ * in ms: its wall time and CPU time (host.ts
6
+ * `cputime`). An externally measured bench spreads the reading into its
7
+ * sample, `{ ...took(), source }`. */ export let stopwatch = (...sources)=>{
8
+ let used = ()=>sources.reduce((total, read)=>total + read(), cputime());
9
+ let cpu = used(), wall = performance.now();
10
+ return ()=>({
11
+ value: performance.now() - wall,
12
+ cpu: used() - cpu
13
+ });
14
+ };
15
+ export let bench = (options)=>{
16
+ let iterations = options.iterations ?? 1;
17
+ let operations = options.operations ?? 1;
18
+ for (let n of [
19
+ iterations,
20
+ operations
21
+ ]){
22
+ if (!Number.isSafeInteger(n) || n < 1) {
23
+ throw new Error('Expected a positive integer count');
24
+ }
25
+ }
26
+ let [unit, per, extra] = options.unit.split('/');
27
+ if (extra != null || per === '' || operations != 1 && !per) {
28
+ throw new Error('Operation normalization needs a unit with a denominator');
29
+ }
30
+ let scales = {
31
+ ns: 1e6,
32
+ us: 1e3,
33
+ ms: 1,
34
+ s: 1e-3
35
+ };
36
+ let scale = scales[unit];
37
+ if (scale == null) throw new Error(`Unknown time unit: ${options.unit}`);
38
+ let target = options.target ?? {};
39
+ return {
40
+ name: options.name,
41
+ unit: options.unit,
42
+ ...options.resolution !== undefined ? {
43
+ resolution: options.resolution
44
+ } : {},
45
+ better: 'lower',
46
+ sample: async (round)=>{
47
+ let out = [];
48
+ for(let iteration = 0; iteration < iterations; iteration++){
49
+ let context = {
50
+ round,
51
+ iteration
52
+ };
53
+ try {
54
+ await options.setup?.(context);
55
+ let timed = ()=>{
56
+ let took = stopwatch();
57
+ let result = options.run(context);
58
+ let done = ()=>{
59
+ let { value, cpu } = took();
60
+ return {
61
+ value: value * scale / operations,
62
+ cpu: cpu * scale / operations,
63
+ counts: {
64
+ operations
65
+ },
66
+ source: 'invocation'
67
+ };
68
+ };
69
+ // A sync workload must not pay for a Promise turn inside its timing.
70
+ return result && typeof result.then == 'function' ? Promise.resolve(result).then(done) : done();
71
+ };
72
+ let captured = await trace.record(target, ()=>options.target ? timed() : trace.during(trace.peek(target)?.begin({
73
+ kind: 'bench',
74
+ name: options.name,
75
+ package: '@yaks/benchmark'
76
+ }), timed));
77
+ out.push({
78
+ ...captured.result,
79
+ spans: captured.spans
80
+ });
81
+ } finally{
82
+ await options.teardown?.(context);
83
+ }
84
+ }
85
+ return out;
86
+ }
87
+ };
88
+ };
89
+ //# sourceMappingURL=bench.js.map
package/bench.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bench.js","sources":["./bench.ts"],"names":[],"mappings":"AAAA;6EAC6E,GAE7E,YAAY,8BAAmC;AAC/C,SAAS,OAAO,oBAAmB;AAmBnC;;;oCAGoC,GACpC,OAAO,IAAI,YAAY,CACrB,GAAG;EAEH,IAAI,OAAO,IAAM,QAAQ,MAAM,CAAC,CAAC,OAAO,OAAS,QAAQ,QAAQ;EACjE,IAAI,MAAM,QAAQ,OAAO,YAAY,GAAG;EACxC,OAAO,IAAM,CAAC;MAAE,OAAO,YAAY,GAAG,KAAK;MAAM,KAAK,SAAS;IAAI,CAAC;AACtE,EAAC;AAED,OAAO,IAAI,QAAQ,CAAC;EAClB,IAAI,aAAa,QAAQ,UAAU,IAAI;EACvC,IAAI,aAAa,QAAQ,UAAU,IAAI;EACvC,KAAK,IAAI,KAAK;IAAC;IAAY;GAAW,CAAE;IACtC,IAAI,CAAC,OAAO,aAAa,CAAC,MAAM,IAAI,GAAG;MACrC,MAAM,IAAI,MAAM;IAClB;EACF;EACA,IAAI,CAAC,MAAM,KAAK,MAAM,GAAG,QAAQ,IAAI,CAAC,KAAK,CAAC;EAC5C,IAAI,SAAS,QAAQ,QAAQ,MAAO,cAAc,KAAK,CAAC,KAAM;IAC5D,MAAM,IAAI,MAAM;EAClB;EACA,IAAI,SAAiC;IAAE,IAAI;IAAK,IAAI;IAAK,IAAI;IAAG,GAAG;EAAK;EACxE,IAAI,QAAQ,MAAM,CAAC,KAAK;EACxB,IAAI,SAAS,MAAM,MAAM,IAAI,MAAM,CAAC,mBAAmB,EAAE,QAAQ,IAAI,EAAE;EACvE,IAAI,SAAS,QAAQ,MAAM,IAAI,CAAC;EAChC,OAAO;IACL,MAAM,QAAQ,IAAI;IAClB,MAAM,QAAQ,IAAI;IAClB,GAAI,QAAQ,UAAU,KAAK,YACvB;MAAE,YAAY,QAAQ,UAAU;IAAC,IACjC,CAAC,CAAC;IACN,QAAQ;IACR,QAAQ,OAAO;MACb,IAAI,MAAgB,EAAE;MACtB,IAAK,IAAI,YAAY,GAAG,YAAY,YAAY,YAAa;QAC3D,IAAI,UAAU;UAAE;UAAO;QAAU;QACjC,IAAI;UACF,MAAM,QAAQ,KAAK,GAAG;UACtB,IAAI,QAAQ;YACV,IAAI,OAAO;YACX,IAAI,SAAS,QAAQ,GAAG,CAAC;YACzB,IAAI,OAAO;cACT,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG;cACrB,OAAO;gBACL,OAAO,QAAQ,QAAQ;gBACvB,KAAK,MAAM,QAAQ;gBACnB,QAAQ;kBAAE;gBAAW;gBACrB,QAAQ;cACV;YACF;YACA,qEAAqE;YACrE,OAAO,UACH,OAAO,AAAC,OAAgC,IAAI,IAAI,aAChD,QAAQ,OAAO,CAAC,QAAQ,IAAI,CAAC,QAC7B;UACN;UACA,IAAI,WAAW,MAAM,MAAM,MAAM,CAC/B,QACA,IACE,QAAQ,MAAM,GAAG,UAAU,MAAM,MAAM,CACrC,MAAM,IAAI,CAAC,SAAS,MAAM;cACxB,MAAM;cACN,MAAM,QAAQ,IAAI;cAClB,SAAS;YACX,IACA;UAGN,IAAI,IAAI,CAAC;YAAE,GAAG,SAAS,MAAM;YAAE,OAAO,SAAS,KAAK;UAAC;QACvD,SAAU;UACR,MAAM,QAAQ,QAAQ,GAAG;QAC3B;MACF;MACA,OAAO;IACT;EACF;AACF,EAAC"}
package/bench.ts ADDED
@@ -0,0 +1,103 @@
1
+ /** Timed sync or async workloads. Setup and teardown are outside each sample;
2
+ * operations normalizes a batch, while iterations keeps individual samples. */
3
+ import type { Bench, Sample, Workload } from './result.ts'
4
+ import * as trace from '@yaks/trace'
5
+ import { cputime } from './host.js'
6
+
7
+ type DurationUnit = 'ns' | 'us' | 'ms' | 's'
8
+ export type TimeUnit = DurationUnit | `${DurationUnit}/${string}`
9
+ export type Iteration = { round: number; iteration: number }
10
+ export type TimedBench = Pick<Workload, 'name' | 'resolution'> & {
11
+ unit: TimeUnit
12
+ run: (iteration: Iteration) => unknown
13
+ /** How many independent timed invocations to keep in each round. */
14
+ iterations?: number
15
+ /** How many operations one invocation performs. */
16
+ operations?: number
17
+ setup?: (iteration: Iteration) => unknown
18
+ teardown?: (iteration: Iteration) => unknown
19
+ /** Record this target's work (for example, a graph). Without a target, the
20
+ * tree contains the bench invocation's own span. */
21
+ target?: object
22
+ }
23
+
24
+ /** Start timing a step; the function it returns says how long it took since,
25
+ * in ms: its wall time and CPU time (host.ts
26
+ * `cputime`). An externally measured bench spreads the reading into its
27
+ * sample, `{ ...took(), source }`. */
28
+ export let stopwatch = (
29
+ ...sources: (() => number)[]
30
+ ): () => { value: number; cpu: number } => {
31
+ let used = () => sources.reduce((total, read) => total + read(), cputime())
32
+ let cpu = used(), wall = performance.now()
33
+ return () => ({ value: performance.now() - wall, cpu: used() - cpu })
34
+ }
35
+
36
+ export let bench = (options: TimedBench): Bench => {
37
+ let iterations = options.iterations ?? 1
38
+ let operations = options.operations ?? 1
39
+ for (let n of [iterations, operations]) {
40
+ if (!Number.isSafeInteger(n) || n < 1) {
41
+ throw new Error('Expected a positive integer count')
42
+ }
43
+ }
44
+ let [unit, per, extra] = options.unit.split('/')
45
+ if (extra != null || per === '' || (operations != 1 && !per)) {
46
+ throw new Error('Operation normalization needs a unit with a denominator')
47
+ }
48
+ let scales: Record<string, number> = { ns: 1e6, us: 1e3, ms: 1, s: 1e-3 }
49
+ let scale = scales[unit]
50
+ if (scale == null) throw new Error(`Unknown time unit: ${options.unit}`)
51
+ let target = options.target ?? {}
52
+ return {
53
+ name: options.name,
54
+ unit: options.unit,
55
+ ...(options.resolution !== undefined
56
+ ? { resolution: options.resolution }
57
+ : {}),
58
+ better: 'lower',
59
+ sample: async (round) => {
60
+ let out: Sample[] = []
61
+ for (let iteration = 0; iteration < iterations; iteration++) {
62
+ let context = { round, iteration }
63
+ try {
64
+ await options.setup?.(context)
65
+ let timed = () => {
66
+ let took = stopwatch()
67
+ let result = options.run(context)
68
+ let done = (): Sample => {
69
+ let { value, cpu } = took()
70
+ return {
71
+ value: value * scale / operations,
72
+ cpu: cpu * scale / operations,
73
+ counts: { operations },
74
+ source: 'invocation',
75
+ }
76
+ }
77
+ // A sync workload must not pay for a Promise turn inside its timing.
78
+ return result &&
79
+ typeof (result as PromiseLike<unknown>).then == 'function'
80
+ ? Promise.resolve(result).then(done)
81
+ : done()
82
+ }
83
+ let captured = await trace.record(
84
+ target,
85
+ () =>
86
+ options.target ? timed() : trace.during(
87
+ trace.peek(target)?.begin({
88
+ kind: 'bench',
89
+ name: options.name,
90
+ package: '@yaks/benchmark',
91
+ }),
92
+ timed,
93
+ ),
94
+ )
95
+ out.push({ ...captured.result, spans: captured.spans })
96
+ } finally {
97
+ await options.teardown?.(context)
98
+ }
99
+ }
100
+ return out
101
+ },
102
+ }
103
+ }
package/deno.js ADDED
@@ -0,0 +1,35 @@
1
+ /** Import CPU invocation averages from the shared Deno workload collector.
2
+ * Keep wall time and collector statistics alongside the CPU measurement. */ import { sameNames } from "./result.js";
3
+ export let extract = (report, expected)=>{
4
+ if (report.version !== 1 || !report.runtime || !report.cpu) {
5
+ throw new Error('Unsupported Deno bench report');
6
+ }
7
+ sameNames(expected.map((name)=>({
8
+ name,
9
+ unit: 'ns/op'
10
+ })), report.benches.map((b)=>({
11
+ name: b.name,
12
+ unit: 'ns/op'
13
+ })));
14
+ return Object.fromEntries(report.benches.map((b)=>{
15
+ let ok = b.results[0]?.ok;
16
+ if (b.results.length != 1 || !ok || b.results[0].failed || !Number.isFinite(ok.avg) || ok.avg <= 0 || !Number.isFinite(ok.cpu) || ok.cpu < 0) {
17
+ throw new Error(`Failed or invalid Deno result: ${b.name}`);
18
+ }
19
+ return [
20
+ b.name,
21
+ {
22
+ value: ok.avg,
23
+ cpu: ok.cpu,
24
+ ...ok.sampling ? {
25
+ sampling: ok.sampling
26
+ } : {},
27
+ source: 'deno-cpu-average',
28
+ details: {
29
+ ...ok
30
+ }
31
+ }
32
+ ];
33
+ }));
34
+ };
35
+ //# sourceMappingURL=deno.js.map
package/deno.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deno.js","sources":["./deno.ts"],"names":[],"mappings":"AAAA;0EAC0E,GAC1E,SAAS,SAAS,sBAAiD;AAmBnE,OAAO,IAAI,UAAU,CACnB,QACA;EAEA,IAAI,OAAO,OAAO,KAAK,KAAK,CAAC,OAAO,OAAO,IAAI,CAAC,OAAO,GAAG,EAAE;IAC1D,MAAM,IAAI,MAAM;EAClB;EACA,UACE,SAAS,GAAG,CAAC,CAAC,OAAS,CAAC;MAAE;MAAM,MAAM;IAAQ,CAAC,IAC/C,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,IAAM,CAAC;MAAE,MAAM,EAAE,IAAI;MAAE,MAAM;IAAQ,CAAC;EAE5D,OAAO,OAAO,WAAW,CAAC,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC;IAC5C,IAAI,KAAK,EAAE,OAAO,CAAC,EAAE,EAAE;IACvB,IACE,EAAE,OAAO,CAAC,MAAM,IAAI,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,MAAM,IACnD,CAAC,OAAO,QAAQ,CAAC,GAAG,GAAG,KAAK,GAAG,GAAG,IAAI,KACtC,CAAC,OAAO,QAAQ,CAAC,GAAG,GAAG,KAAK,GAAG,GAAG,GAAI,GACtC;MACA,MAAM,IAAI,MAAM,CAAC,+BAA+B,EAAE,EAAE,IAAI,EAAE;IAC5D;IACA,OAAO;MAAC,EAAE,IAAI;MAAE;QACd,OAAO,GAAG,GAAG;QACb,KAAK,GAAG,GAAG;QACX,GAAG,GAAG,QAAQ,GAAG;UAAE,UAAU,GAAG,QAAQ;QAAC,IAAI,CAAC,CAAC;QAC/C,QAAQ;QACR,SAAS;UAAE,GAAG,EAAE;QAAC;MACnB;KAAE;EACJ;AACF,EAAC"}
package/deno.json ADDED
@@ -0,0 +1 @@
1
+ {"publish":{"exclude":["**/*_test.ts"]},"name":"@yaks/benchmark","version":"0.2.36","license":"Apache-2.0","description":"Named workloads, raw samples, JSON runs and explicit baseline ratchets, with process-configured reporters.","exports":{".":"./mod.ts","./deno":"./deno.ts"},"imports":{"@yaks/benchmark":"./mod.ts","@yaks/benchmark/deno":"./deno.ts"}}
package/deno.ts ADDED
@@ -0,0 +1,50 @@
1
+ /** Import CPU invocation averages from the shared Deno workload collector.
2
+ * Keep wall time and collector statistics alongside the CPU measurement. */
3
+ import { sameNames, type Sample, type Sampling } from './result.js'
4
+
5
+ export type DenoReport = {
6
+ version: number
7
+ runtime: string
8
+ cpu: string
9
+ benches: {
10
+ name: string
11
+ results: {
12
+ ok?: {
13
+ avg: number
14
+ cpu?: number
15
+ sampling?: Sampling
16
+ [key: string]: unknown
17
+ }
18
+ failed?: unknown
19
+ }[]
20
+ }[]
21
+ }
22
+ export let extract = (
23
+ report: DenoReport,
24
+ expected: readonly string[],
25
+ ): Record<string, Sample> => {
26
+ if (report.version !== 1 || !report.runtime || !report.cpu) {
27
+ throw new Error('Unsupported Deno bench report')
28
+ }
29
+ sameNames(
30
+ expected.map((name) => ({ name, unit: 'ns/op' })),
31
+ report.benches.map((b) => ({ name: b.name, unit: 'ns/op' })),
32
+ )
33
+ return Object.fromEntries(report.benches.map((b) => {
34
+ let ok = b.results[0]?.ok
35
+ if (
36
+ b.results.length != 1 || !ok || b.results[0].failed ||
37
+ !Number.isFinite(ok.avg) || ok.avg <= 0 ||
38
+ !Number.isFinite(ok.cpu) || ok.cpu! < 0
39
+ ) {
40
+ throw new Error(`Failed or invalid Deno result: ${b.name}`)
41
+ }
42
+ return [b.name, {
43
+ value: ok.avg,
44
+ cpu: ok.cpu,
45
+ ...ok.sampling ? { sampling: ok.sampling } : {},
46
+ source: 'deno-cpu-average',
47
+ details: { ...ok },
48
+ }]
49
+ }))
50
+ }