@ac-bench/util 0.1.13 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,117 @@
1
1
  # @ac-bench/util
2
2
 
3
+ ## 0.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 5c203e7: `zod` is now a required peer dependency (`^4.5.4`), passed on from
8
+ `@ac-kit/app-report`, which this package depends on.
9
+
10
+ Migration: add `zod` to your project's dependencies if it is not there already.
11
+ - 5c203e7: Browser entries. Each measure package and `@ac-bench/util` adds a `"browser"`
12
+ condition to its `"."` export (`index.browser.ts`, mirrored in
13
+ `publishConfig`), with the same registration API and no `node:` import, so a
14
+ suite mixing measures bundles for a page. What a page cannot do fails the case
15
+ alone with `UnsupportedInRuntimeError` (`unsupported-in-runtime`, new in
16
+ `@ac-bench/core/runner`): duration's spawned processes (per-iteration
17
+ processes, command cases, spawn baselines), jitter's event-loop monitor,
18
+ constant-time's nanosecond clock. Each plugin's `supportsRuntime` lets the
19
+ parent skip what cannot run without a launch: duration runs everywhere,
20
+ resource in Node and Chromium-family runtimes, jitter and constant-time in
21
+ Node only.
22
+
23
+ Resource measures in Chromium through `performance.memory` (allocation source
24
+ `browser-heap-growth`): its `scheduling.browser` asks for
25
+ `--enable-precise-memory-info` and `--js-flags=--expose-gc
26
+ --min-semi-space-size=64 --max-semi-space-size=64`, batches are capped below
27
+ half the young generation, an allocation self-check at the first case warns
28
+ `allocation-probe-failed` when the counter is off by more than 10 %, and CPU
29
+ time, which a page cannot read, is reported 0 with a `cpu-time-unavailable`
30
+ warning. Batches are sized by wall time where CPU time reads 0.
31
+
32
+ `@ac-bench/util` adds `assertSameResult(contender, actual, expected)`: an
33
+ equivalence check for suites meant for browsers (`Object.is` on numbers,
34
+ element-wise on arrays and typed arrays, `isDeepEqual` otherwise), naming the
35
+ contender and the first differing index. Its package now has an `exports` map:
36
+ deep imports are no longer reachable.
37
+
38
+ The measure packages' Node entries now have a side effect (installing their
39
+ Node host), declared in `sideEffects`.
40
+
41
+ ### Patch Changes
42
+
43
+ - 5c203e7: The `homepage` points at the @ac-bench documentation site: `measure(1)` for the CLI, the API reference for `core`, `lib` and `gate`, the site's home for the others.
44
+ - Updated dependencies [5c203e7]
45
+ - Updated dependencies [5c203e7]
46
+ - Updated dependencies [5c203e7]
47
+ - Updated dependencies [5c203e7]
48
+ - Updated dependencies [5c203e7]
49
+ - Updated dependencies [5c203e7]
50
+ - Updated dependencies [5c203e7]
51
+ - Updated dependencies [5c203e7]
52
+ - Updated dependencies [5c203e7]
53
+ - Updated dependencies [5c203e7]
54
+ - Updated dependencies [5c203e7]
55
+ - Updated dependencies [5c203e7]
56
+ - Updated dependencies [5c203e7]
57
+ - Updated dependencies [5c203e7]
58
+ - @ac-kit/algo@0.7.0
59
+ - @ac-kit/app-system@0.8.0
60
+ - @ac-kit/core@0.14.0
61
+ - @ac-kit/math-stats@0.7.0
62
+ - @ac-kit/node@0.13.0
63
+ - @ac-kit/noncrypto-hash@0.3.0
64
+ - @ac-kit/text-unicode@0.2.1
65
+ - @ac-kit/math-random@0.4.2
66
+ - @ac-kit/test-util@0.5.1
67
+
68
+ ## 0.1.14
69
+
70
+ ### Patch Changes
71
+
72
+ - Updated dependencies [0b4fe43]
73
+ - Updated dependencies [0b4fe43]
74
+ - Updated dependencies [0b4fe43]
75
+ - Updated dependencies [0b4fe43]
76
+ - Updated dependencies [0b4fe43]
77
+ - Updated dependencies [0b4fe43]
78
+ - Updated dependencies [0b4fe43]
79
+ - Updated dependencies [0b4fe43]
80
+ - Updated dependencies [0b4fe43]
81
+ - Updated dependencies [0b4fe43]
82
+ - Updated dependencies [0b4fe43]
83
+ - Updated dependencies [0b4fe43]
84
+ - Updated dependencies [0b4fe43]
85
+ - Updated dependencies [0b4fe43]
86
+ - Updated dependencies [0b4fe43]
87
+ - Updated dependencies [0b4fe43]
88
+ - Updated dependencies [0b4fe43]
89
+ - Updated dependencies [0b4fe43]
90
+ - Updated dependencies [0b4fe43]
91
+ - Updated dependencies [0b4fe43]
92
+ - Updated dependencies [0b4fe43]
93
+ - Updated dependencies [0b4fe43]
94
+ - Updated dependencies [0b4fe43]
95
+ - Updated dependencies [0b4fe43]
96
+ - Updated dependencies [0b4fe43]
97
+ - Updated dependencies [0b4fe43]
98
+ - Updated dependencies [0b4fe43]
99
+ - Updated dependencies [0b4fe43]
100
+ - Updated dependencies [0b4fe43]
101
+ - Updated dependencies [0b4fe43]
102
+ - Updated dependencies [0b4fe43]
103
+ - Updated dependencies [0b4fe43]
104
+ - Updated dependencies [0b4fe43]
105
+ - @ac-kit/algo@0.6.0
106
+ - @ac-kit/core@0.13.0
107
+ - @ac-kit/math-stats@0.6.0
108
+ - @ac-kit/node@0.12.0
109
+ - @ac-kit/app-system@0.7.1
110
+ - @ac-kit/test-util@0.5.0
111
+ - @ac-kit/text-unicode@0.2.0
112
+ - @ac-kit/math-random@0.4.1
113
+ - @ac-kit/noncrypto-hash@0.2.3
114
+
3
115
  ## 0.1.13
4
116
 
5
117
  ### Patch Changes
package/README.md CHANGED
@@ -18,13 +18,18 @@ const expected = checksum(reference(values));
18
18
  // ... assert each candidate reproduces `expected` before trusting its timing.
19
19
  ```
20
20
 
21
+ `zod` is a peer dependency (`^4.5.4`), passed on from `@ac-kit/app-report`:
22
+ install it beside this package.
23
+
21
24
  ## What it exposes
22
25
 
23
26
  - **Seeded workloads** — `randomFloat64Values`, `randomUint32Values`,
24
27
  `randomInts`, `words`, `skewedIndices`, `distinctKeys`, and `DEFAULT_SEED`.
25
28
  - **Equivalence** — `checksum`, `sequentialChecksum`, `hashString`,
26
29
  `stringHash32`: order-sensitive digests for proving two implementations
27
- produced the same output.
30
+ produced the same output; `assertSameResult(contender, actual, expected)`
31
+ throws naming the contender and the first differing index (`Object.is` on
32
+ numbers, element-wise on arrays and typed arrays), without `node:assert`.
28
33
  - **Contention** — `EventLoopLoad`, a controllable background load, for
29
34
  measuring the same operation idle and under pressure.
30
35
  - **Native toolchains** — `prepareNativeToolchains`, for suites comparing
@@ -34,3 +39,7 @@ Generic process helpers (`execAsync`, `hasBinary`, `createTempDir`) are
34
39
  `@ac-kit/node`'s — they carry no measurement-specific semantics. Spawn-overhead
35
40
  calibration lives with the measure that needs it, in
36
41
  `@ac-bench/measure-duration`.
42
+
43
+ The `"browser"` export condition selects a portable entry for suites run in a
44
+ browser: the workload fixtures, the digests and `assertSameResult`;
45
+ `EventLoopLoad` and the native toolchains are Node-only.
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Throws when `actual` differs from `expected`, for the equivalence checks a
3
+ * suite runs before measuring contenders against each other — without
4
+ * `node:assert`, so the suite also runs in a browser.
5
+ *
6
+ * Numbers compare with `Object.is` (so `-0` and `NaN` count), arrays and typed
7
+ * arrays element-wise with the same rule, anything else with `isDeepEqual`
8
+ * (`@ac-kit/core`, `"sameValue"`). The message names the contender and the
9
+ * first differing index.
10
+ *
11
+ * @param contender Which implementation produced `actual`, for the message.
12
+ * @param actual Its result.
13
+ * @param expected The reference result.
14
+ * @throws {Error} The results differ.
15
+ */
16
+ export declare function assertSameResult(contender: string, actual: unknown, expected: unknown): void;
17
+ //# sourceMappingURL=assert-same-result.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assert-same-result.d.ts","sourceRoot":"","sources":["../src/assert-same-result.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,gBAAgB,CAC/B,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,OAAO,EACf,QAAQ,EAAE,OAAO,GACf,IAAI,CAKN"}
@@ -0,0 +1,68 @@
1
+ import { isDeepEqual } from "@ac-kit/core";
2
+ /**
3
+ * Throws when `actual` differs from `expected`, for the equivalence checks a
4
+ * suite runs before measuring contenders against each other — without
5
+ * `node:assert`, so the suite also runs in a browser.
6
+ *
7
+ * Numbers compare with `Object.is` (so `-0` and `NaN` count), arrays and typed
8
+ * arrays element-wise with the same rule, anything else with `isDeepEqual`
9
+ * (`@ac-kit/core`, `"sameValue"`). The message names the contender and the
10
+ * first differing index.
11
+ *
12
+ * @param contender Which implementation produced `actual`, for the message.
13
+ * @param actual Its result.
14
+ * @param expected The reference result.
15
+ * @throws {Error} The results differ.
16
+ */
17
+ export function assertSameResult(contender, actual, expected) {
18
+ const difference = firstDifference_(actual, expected);
19
+ if (difference !== null) {
20
+ throw new Error(`${contender} disagrees with the reference: ${difference}`);
21
+ }
22
+ }
23
+ function isIndexed_(value) {
24
+ return (Array.isArray(value) ||
25
+ (ArrayBuffer.isView(value) && !(value instanceof DataView)));
26
+ }
27
+ function firstDifference_(actual, expected) {
28
+ if (typeof actual === "number" && typeof expected === "number") {
29
+ return Object.is(actual, expected)
30
+ ? null
31
+ : `${describe_(actual)} instead of ${describe_(expected)}`;
32
+ }
33
+ if (isIndexed_(actual) && isIndexed_(expected)) {
34
+ if (actual.length !== expected.length) {
35
+ return `length ${actual.length} instead of ${expected.length}`;
36
+ }
37
+ for (let index = 0; index < expected.length; index++) {
38
+ const left = actual[index];
39
+ const right = expected[index];
40
+ const same = typeof left === "number" && typeof right === "number"
41
+ ? Object.is(left, right)
42
+ : isDeepEqual(left, right, "sameValue");
43
+ if (!same) {
44
+ return `index ${index} is ${describe_(left)} instead of ${describe_(right)}`;
45
+ }
46
+ }
47
+ return null;
48
+ }
49
+ return isDeepEqual(actual, expected, "sameValue")
50
+ ? null
51
+ : `${describe_(actual)} instead of ${describe_(expected)}`;
52
+ }
53
+ function describe_(value) {
54
+ if (typeof value === "number") {
55
+ return Object.is(value, -0) ? "-0" : String(value);
56
+ }
57
+ if (typeof value === "bigint") {
58
+ return `${value}n`;
59
+ }
60
+ if (typeof value === "string") {
61
+ return JSON.stringify(value);
62
+ }
63
+ if (isIndexed_(value)) {
64
+ return `${value.constructor.name}(${value.length})`;
65
+ }
66
+ return Object.prototype.toString.call(value);
67
+ }
68
+ //# sourceMappingURL=assert-same-result.js.map
@@ -0,0 +1 @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,CAAC,EAAE,CAAC;QACvB,OAAO,GAAG,KAAK,CAAC,WAAW,CAAC,IAAI,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;IACrD,CAAC;IAED,OAAO,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC9C,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The portable entry, selected by the `"browser"` export condition: what a
3
+ * suite meant for browsers may import. The event-loop load and the native
4
+ * toolchain are Node-only and stay in the Node entry.
5
+ */
6
+ export * from "./assert-same-result.js";
7
+ export * from "./fixtures.js";
8
+ //# sourceMappingURL=index.browser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.browser.d.ts","sourceRoot":"","sources":["../src/index.browser.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,cAAc,yBAAyB,CAAC;AACxC,cAAc,eAAe,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The portable entry, selected by the `"browser"` export condition: what a
3
+ * suite meant for browsers may import. The event-loop load and the native
4
+ * toolchain are Node-only and stay in the Node entry.
5
+ */
6
+ export * from "./assert-same-result.js";
7
+ export * from "./fixtures.js";
8
+ //# sourceMappingURL=index.browser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.browser.js","sourceRoot":"","sources":["../src/index.browser.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,cAAc,yBAAyB,CAAC;AACxC,cAAc,eAAe,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from "./assert-same-result.js";
1
2
  export * from "./event-loop-load.js";
2
3
  export * from "./fixtures.js";
3
4
  export * from "./native-toolchain.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AACrC,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC"}
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ export * from "./assert-same-result.js";
1
2
  export * from "./event-loop-load.js";
2
3
  export * from "./fixtures.js";
3
4
  export * from "./native-toolchain.js";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AACrC,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ac-bench/util",
3
- "version": "0.1.13",
3
+ "version": "0.2.0",
4
4
  "description": "Helpers for writing benchmarks: deterministic PRNG workloads, an order-sensitive output hash, an equivalence guard, a controllable event-loop load, and spawn-overhead measurement.",
5
5
  "keywords": [
6
6
  "benchmark",
@@ -8,7 +8,7 @@
8
8
  "prng",
9
9
  "workload"
10
10
  ],
11
- "homepage": "https://git.grenadine.io/anthochamp/node-essentials/src/branch/main/bench/util#readme",
11
+ "homepage": "https://anthochamp.pages.grenadine.io/node-essentials/bench/",
12
12
  "bugs": {
13
13
  "url": "https://git.grenadine.io/anthochamp/node-essentials/issues"
14
14
  },
@@ -25,8 +25,20 @@
25
25
  "type": "module",
26
26
  "sideEffects": false,
27
27
  "main": "./dist/index.js",
28
+ "exports": {
29
+ ".": {
30
+ "browser": "./dist/index.browser.js",
31
+ "default": "./dist/index.js"
32
+ }
33
+ },
28
34
  "publishConfig": {
29
35
  "main": "./dist/index.js",
36
+ "exports": {
37
+ ".": {
38
+ "browser": "./dist/index.browser.js",
39
+ "default": "./dist/index.js"
40
+ }
41
+ },
30
42
  "access": "public"
31
43
  },
32
44
  "scripts": {
@@ -38,27 +50,31 @@
38
50
  "prepack": "yarn build"
39
51
  },
40
52
  "dependencies": {
41
- "@ac-kit/algo": "^0.5.0",
42
- "@ac-kit/app-system": "^0.7.0",
43
- "@ac-kit/core": "^0.12.0",
44
- "@ac-kit/math-random": "^0.4.0",
45
- "@ac-kit/math-stats": "^0.5.0",
46
- "@ac-kit/node": "^0.11.0",
47
- "@ac-kit/noncrypto-hash": "^0.2.2",
48
- "@ac-kit/test-util": "^0.4.0",
49
- "@ac-kit/text-unicode": "^0.1.0"
53
+ "@ac-kit/algo": "^0.7.0",
54
+ "@ac-kit/app-system": "^0.8.0",
55
+ "@ac-kit/core": "^0.14.0",
56
+ "@ac-kit/math-random": "^0.4.2",
57
+ "@ac-kit/math-stats": "^0.7.0",
58
+ "@ac-kit/node": "^0.13.0",
59
+ "@ac-kit/noncrypto-hash": "^0.3.0",
60
+ "@ac-kit/test-util": "^0.5.1",
61
+ "@ac-kit/text-unicode": "^0.2.1"
50
62
  },
51
63
  "devDependencies": {
52
64
  "@ac-kit/tsconfig": "0.1.0",
53
65
  "@ac-kit/typedoc-config": "0.1.0",
54
- "@ac-kit/vitest-config": "0.2.0",
66
+ "@ac-kit/vitest-config": "0.3.0",
55
67
  "@types/node": "26.6.11",
56
68
  "@typescript/native": "typescript@7.0.2",
57
69
  "rimraf": "6.1.4",
58
70
  "typedoc": "0.28.20",
59
71
  "typescript": "@typescript/typescript6@6.0.2",
60
72
  "vite": "8.4.0",
61
- "vitest": "5.1.2"
73
+ "vitest": "5.1.2",
74
+ "zod": "^4.5.4"
75
+ },
76
+ "peerDependencies": {
77
+ "zod": "^4.5.4"
62
78
  },
63
79
  "engines": {
64
80
  "node": ">=24"