@abide/harness 0.2.1 → 0.3.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/package.json +6 -3
- package/src/measure/install.ts +3 -3
- package/src/runner/harnessBench.ts +24 -0
- package/src/runner/index.ts +5 -3
- package/src/runner/runBenches.ts +96 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abide/harness",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Ratios against hand-written code, counts of the work an op did, and gates whose revert can be run — three measurement lanes for anything that renders, on bun",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"playwright"
|
|
24
24
|
],
|
|
25
25
|
"engines": {
|
|
26
|
-
"bun": ">=1.4.
|
|
26
|
+
"bun": ">=1.4.4"
|
|
27
27
|
},
|
|
28
28
|
"publishConfig": {
|
|
29
29
|
"access": "public",
|
|
@@ -33,6 +33,9 @@
|
|
|
33
33
|
"src",
|
|
34
34
|
"scripts/buildInjectable.ts"
|
|
35
35
|
],
|
|
36
|
+
"bin": {
|
|
37
|
+
"harness-bench": "./src/runner/harnessBench.ts"
|
|
38
|
+
},
|
|
36
39
|
"exports": {
|
|
37
40
|
"./measure": "./src/measure/index.ts",
|
|
38
41
|
"./preload": "./src/measure/preload.ts",
|
|
@@ -55,7 +58,7 @@
|
|
|
55
58
|
},
|
|
56
59
|
"peerDependencies": {
|
|
57
60
|
"@playwright/test": "^1.64.0",
|
|
58
|
-
"@abide/abide": ">=0.
|
|
61
|
+
"@abide/abide": ">=0.117.1"
|
|
59
62
|
},
|
|
60
63
|
"peerDependenciesMeta": {
|
|
61
64
|
"@playwright/test": {
|
package/src/measure/install.ts
CHANGED
|
@@ -82,6 +82,7 @@ const DECLARED: [interfaceName: string, member: string, role: Role][] = [
|
|
|
82
82
|
['Document', 'prepend', 'insertArgs'],
|
|
83
83
|
['Document', 'replaceChildren', 'replaceChildren'],
|
|
84
84
|
['Element', 'setAttribute', 'attribute'],
|
|
85
|
+
['Element', 'setAttributeNS', 'attribute'],
|
|
85
86
|
['Element', 'removeAttribute', 'attribute'],
|
|
86
87
|
['Element', 'toggleAttribute', 'attribute'],
|
|
87
88
|
['Element', 'className', 'attribute'],
|
|
@@ -91,13 +92,14 @@ const DECLARED: [interfaceName: string, member: string, role: Role][] = [
|
|
|
91
92
|
// happy-dom gives `HTMLTemplateElement` its OWN `innerHTML`, which shadows the one
|
|
92
93
|
// above — so a `template.innerHTML` write reaches no patched member, the
|
|
93
94
|
// outermost-only guard never engages, and the parse's internal `createElementNS`
|
|
94
|
-
//
|
|
95
|
+
// calls are counted as creates of their own instead. The compiled arm makes every row from a
|
|
95
96
|
// template, so that is the whole arm. Chromium has no own descriptor here and the
|
|
96
97
|
// installer shadows, which is how the two lists stay identical.
|
|
97
98
|
['HTMLTemplateElement', 'innerHTML', 'html'],
|
|
98
99
|
['Element', 'outerHTML', 'html'],
|
|
99
100
|
['CharacterData', 'data', 'data'],
|
|
100
101
|
['Document', 'createElement', 'create'],
|
|
102
|
+
['Document', 'createElementNS', 'create'],
|
|
101
103
|
['Document', 'createTextNode', 'create'],
|
|
102
104
|
['Document', 'createComment', 'create'],
|
|
103
105
|
['Document', 'importNode', 'create'],
|
|
@@ -127,7 +129,6 @@ const DECLARED: [interfaceName: string, member: string, role: Role][] = [
|
|
|
127
129
|
['Node', 'normalize', 'refused'],
|
|
128
130
|
['Node', 'nodeValue', 'refused'],
|
|
129
131
|
['Element', 'insertAdjacentText', 'refused'],
|
|
130
|
-
['Element', 'setAttributeNS', 'refused'],
|
|
131
132
|
['Element', 'removeAttributeNS', 'refused'],
|
|
132
133
|
['Element', 'setAttributeNode', 'refused'],
|
|
133
134
|
['Element', 'removeAttributeNode', 'refused'],
|
|
@@ -138,7 +139,6 @@ const DECLARED: [interfaceName: string, member: string, role: Role][] = [
|
|
|
138
139
|
['CharacterData', 'replaceData', 'refused'],
|
|
139
140
|
['Text', 'splitText', 'refused'],
|
|
140
141
|
['Document', 'write', 'refused'],
|
|
141
|
-
['Document', 'createElementNS', 'refused'],
|
|
142
142
|
]
|
|
143
143
|
|
|
144
144
|
/** A fresh `Work` with every counted row at 0 and the three published rows at `null`. */
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
// `harness-bench [word]`: every bench under `src/` of the directory it runs in (`runBenches`), one
|
|
3
|
+
// block each, and exit 1 after listing every arm over its ceiling and every ceiling naming no arm
|
|
4
|
+
// or no bench.
|
|
5
|
+
|
|
6
|
+
import { runBenches } from './runBenches.ts'
|
|
7
|
+
|
|
8
|
+
const over: string[] = []
|
|
9
|
+
for (const bench of await runBenches(process.cwd(), process.argv[2])) {
|
|
10
|
+
for (const line of bench.over)
|
|
11
|
+
over.push(`${bench.file} ${bench.name}: ${line}`)
|
|
12
|
+
// A ceiling naming no bench (43.32) has nothing to print but its line above.
|
|
13
|
+
if (bench.case === '') continue
|
|
14
|
+
let times = ''
|
|
15
|
+
for (const [arm, nanoseconds] of Object.entries(bench.arms))
|
|
16
|
+
times += `${times === '' ? '' : ' · '}${arm} ${(nanoseconds / 1e6).toFixed(3)} ms`
|
|
17
|
+
console.log(
|
|
18
|
+
`${bench.file} ${bench.name}: ${bench.case}\n ${times}\n ${bench.claim}`,
|
|
19
|
+
)
|
|
20
|
+
}
|
|
21
|
+
if (over.length > 0) {
|
|
22
|
+
console.error(`\nOver the ceiling:\n ${over.join('\n ')}`)
|
|
23
|
+
process.exit(1)
|
|
24
|
+
}
|
package/src/runner/index.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
// RUNNERS
|
|
2
|
-
//
|
|
3
|
-
//
|
|
1
|
+
// RUNNERS. A row runner is a subprocess writing one JSON row per line, so a page or a terminal
|
|
2
|
+
// reading it never shares the process a suite or a bench runs in — its clock, its heap, its event
|
|
3
|
+
// loop. `@abide/harness/rows` is the contract the rows keep; this is what writes them.
|
|
4
|
+
// `runBenches` runs an app's benches in its own process, and `harness-bench` is it as a command.
|
|
4
5
|
//
|
|
5
6
|
// Not a lane: it depends on bun and on whichever test runner a suite names, and it measures
|
|
6
7
|
// nothing itself.
|
|
7
8
|
|
|
8
9
|
export { rowsCommand } from './rowsCommand.ts'
|
|
10
|
+
export { runBenches } from './runBenches.ts'
|
|
9
11
|
export { type TestSuite, testRows } from './testRows.ts'
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { type Batched, claimOf, ratio } from '../report/index.ts'
|
|
2
|
+
|
|
3
|
+
const milliseconds = (nanoseconds: number) =>
|
|
4
|
+
`${(nanoseconds / 1e6).toFixed(3)} ms`
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Every bench beside the code, `src/**\/*.bench.ts` under `root`, run in this process one after
|
|
8
|
+
* another: each function a file exports is one bench, and its `CEILINGS` names the most each arm
|
|
9
|
+
* may take, in milliseconds, keyed by bench and then by arm. A ceiling naming no exported bench
|
|
10
|
+
* is reported as a bench of that name with no arms.
|
|
11
|
+
*
|
|
12
|
+
* `only` keeps the files whose path holds it.
|
|
13
|
+
*/
|
|
14
|
+
export async function runBenches(
|
|
15
|
+
root: string,
|
|
16
|
+
only?: string,
|
|
17
|
+
): Promise<
|
|
18
|
+
{
|
|
19
|
+
file: string
|
|
20
|
+
name: string
|
|
21
|
+
case: string
|
|
22
|
+
n: number
|
|
23
|
+
floor: number
|
|
24
|
+
/** Nanoseconds per operation, by arm. */
|
|
25
|
+
arms: Record<string, number>
|
|
26
|
+
/** The last arm over the first, as the harness is allowed to say it; '' for one arm. */
|
|
27
|
+
claim: string
|
|
28
|
+
/** An arm over its ceiling, and a ceiling naming no arm or no bench. */
|
|
29
|
+
over: string[]
|
|
30
|
+
}[]
|
|
31
|
+
> {
|
|
32
|
+
const base = root.endsWith('/') ? root : `${root}/`
|
|
33
|
+
const files = [...new Bun.Glob('src/**/*.bench.ts').scanSync(base)].sort()
|
|
34
|
+
const benches = []
|
|
35
|
+
for (const file of files) {
|
|
36
|
+
if (only !== undefined && !file.includes(only)) continue
|
|
37
|
+
const { CEILINGS = {}, ...exported } = (await import(
|
|
38
|
+
Bun.pathToFileURL(`${base}${file}`).href
|
|
39
|
+
)) as {
|
|
40
|
+
CEILINGS?: Record<string, Record<string, number>>
|
|
41
|
+
} & Record<string, unknown>
|
|
42
|
+
for (const [name, priced] of Object.entries(exported)) {
|
|
43
|
+
if (typeof priced !== 'function') continue
|
|
44
|
+
// `batch` keeps its A/A control out of `samples`, so every sample is an arm.
|
|
45
|
+
const run = (priced as () => Batched)()
|
|
46
|
+
const arms: Record<string, number> = {}
|
|
47
|
+
const names = Object.keys(run.samples)
|
|
48
|
+
for (const arm of names)
|
|
49
|
+
arms[arm] = (
|
|
50
|
+
run.samples[arm] as Batched['samples'][string]
|
|
51
|
+
).nanoseconds
|
|
52
|
+
const first = run.samples[names[0] ?? '']
|
|
53
|
+
const last = run.samples[names[names.length - 1] ?? '']
|
|
54
|
+
const over: string[] = []
|
|
55
|
+
for (const [arm, most] of Object.entries(CEILINGS[name] ?? {})) {
|
|
56
|
+
const took = arms[arm]
|
|
57
|
+
if (took === undefined)
|
|
58
|
+
over.push(`no arm "${arm}" to hold to its ceiling`)
|
|
59
|
+
else if (took / 1e6 > most)
|
|
60
|
+
over.push(
|
|
61
|
+
`${arm} took ${milliseconds(took)}, over its ceiling of ${most} ms`,
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
benches.push({
|
|
65
|
+
file,
|
|
66
|
+
name,
|
|
67
|
+
case: run.case,
|
|
68
|
+
n: run.n,
|
|
69
|
+
floor: run.floor,
|
|
70
|
+
arms,
|
|
71
|
+
claim:
|
|
72
|
+
first && last && first !== last
|
|
73
|
+
? `${last.arm} against ${first.arm}: ${claimOf(
|
|
74
|
+
ratio(last, first, { floor: run.floor }),
|
|
75
|
+
)}`
|
|
76
|
+
: '',
|
|
77
|
+
over,
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
// 43.32 — a ceiling whose bench is not exported holds nothing, so it is reported as a bench
|
|
81
|
+
// with no arms rather than passed over.
|
|
82
|
+
for (const name of Object.keys(CEILINGS))
|
|
83
|
+
if (typeof exported[name] !== 'function')
|
|
84
|
+
benches.push({
|
|
85
|
+
file,
|
|
86
|
+
name,
|
|
87
|
+
case: '',
|
|
88
|
+
n: 0,
|
|
89
|
+
floor: 0,
|
|
90
|
+
arms: {},
|
|
91
|
+
claim: '',
|
|
92
|
+
over: [`no bench "${name}" to hold to its ceiling`],
|
|
93
|
+
})
|
|
94
|
+
}
|
|
95
|
+
return benches
|
|
96
|
+
}
|