punctilio 3.7.2 → 3.7.4

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.
@@ -1,33 +0,0 @@
1
- /**
2
- * Shared test utilities for punctilio test suites.
3
- */
4
- /**
5
- * Builds a deterministic pseudo-random string of approximately `charCount`
6
- * characters by randomly sampling from FRAGMENTS using a seeded PRNG.
7
- *
8
- * @param charCount - Approximate desired character count
9
- * @param seed - PRNG seed (default: "42")
10
- */
11
- export declare function buildMixedContent(charCount: number, seed?: string): string;
12
- /**
13
- * Asserts that a function scales linearly (not quadratically) with input size.
14
- *
15
- * Compares ms/char at the two largest of 4 input sizes (4x vs 8x of startingN)
16
- * after a JIT warmup pass. For a linear algorithm, doubling input keeps ms/char
17
- * constant (ratio ~1). For a quadratic one, doubling input doubles ms/char (~2).
18
- *
19
- * Default startingN of 5000 produces inputs from ~5K to ~40K chars, which is
20
- * past V8's string allocation overhead inflection point where ms/char stabilizes.
21
- *
22
- * Each trial measures `fn` and a known-linear baseline back-to-back at both
23
- * sizes, then divides `fn`'s 8x/4x ratio by the baseline's. Shared platform
24
- * noise (CPU contention, scheduler jitter) inflates both numerator and
25
- * denominator and cancels out; only `fn`-specific super-linear growth pushes
26
- * the normalized ratio past 1. Min across trials picks the cleanest sample.
27
- *
28
- * @param fn - The function to benchmark
29
- * @param buildInput - Builds an input string of approximately `n` units
30
- * @param startingN - Size parameter for the smallest input (default: 5000)
31
- */
32
- export declare function assertLinearScaling(fn: (input: string) => unknown, buildInput: (n: number) => string, startingN?: number): void;
33
- //# sourceMappingURL=test-helpers.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"test-helpers.d.ts","sourceRoot":"","sources":["../../src/tests/test-helpers.ts"],"names":[],"mappings":"AAAA;;GAEG;AAgCH;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,GAAE,MAAa,GAAG,MAAM,CAQhF;AAUD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,mBAAmB,CACjC,EAAE,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,EAC9B,UAAU,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,EACjC,SAAS,GAAE,MAAa,GACvB,IAAI,CAwCN"}
@@ -1,109 +0,0 @@
1
- /**
2
- * Shared test utilities for punctilio test suites.
3
- */
4
- import seedrandom from "seedrandom";
5
- /**
6
- * Fragments covering every transform type: quotes, dashes, apostrophes,
7
- * ellipses, multiplication, math symbols, legal symbols, arrows, primes,
8
- * fractions, degrees, ordinals, nbsp-triggering short words, and plain text.
9
- */
10
- const FRAGMENTS = [
11
- `"Hello," she said. `,
12
- `It's a beautiful day -- isn't it? `,
13
- `Wait... `,
14
- `The temperature was 20 C. `,
15
- `5x5 != 25. `,
16
- `Add 1/2 cup. `,
17
- `He's 5'10" tall. `,
18
- `(c) 2024 Acme Corp. `,
19
- `See p. 42 for details. `,
20
- `Dr. Smith arrived. `,
21
- `The 1st place winner. `,
22
- `Go -> click -> done. `,
23
- `Really?! No way!! `,
24
- `A B C D E F G H. `,
25
- `Pages 10-20 contain important info. `,
26
- `January-March was cold. `,
27
- `The value is -5. `,
28
- `"Don't stop," he said, "keep going." `,
29
- `J. K. Rowling wrote it. `,
30
- `100 km in 2 hrs. `,
31
- ];
32
- /**
33
- * Builds a deterministic pseudo-random string of approximately `charCount`
34
- * characters by randomly sampling from FRAGMENTS using a seeded PRNG.
35
- *
36
- * @param charCount - Approximate desired character count
37
- * @param seed - PRNG seed (default: "42")
38
- */
39
- export function buildMixedContent(charCount, seed = "42") {
40
- const random = seedrandom(seed);
41
- let result = "";
42
- while (result.length < charCount) {
43
- const index = Math.floor(random() * FRAGMENTS.length);
44
- result += FRAGMENTS[index];
45
- }
46
- return result;
47
- }
48
- /**
49
- * Provably linear baseline: a single regex pass that touches every char and
50
- * exercises the same V8 String.replace path the production transforms use.
51
- * Its ms/char ratio is the platform's "what linear looks like right now"
52
- * fingerprint — we divide fn's ratio by it to cancel shared CPU/GC noise.
53
- */
54
- const linearBaseline = (s) => s.replace(/[a-z]/gi, "x");
55
- /**
56
- * Asserts that a function scales linearly (not quadratically) with input size.
57
- *
58
- * Compares ms/char at the two largest of 4 input sizes (4x vs 8x of startingN)
59
- * after a JIT warmup pass. For a linear algorithm, doubling input keeps ms/char
60
- * constant (ratio ~1). For a quadratic one, doubling input doubles ms/char (~2).
61
- *
62
- * Default startingN of 5000 produces inputs from ~5K to ~40K chars, which is
63
- * past V8's string allocation overhead inflection point where ms/char stabilizes.
64
- *
65
- * Each trial measures `fn` and a known-linear baseline back-to-back at both
66
- * sizes, then divides `fn`'s 8x/4x ratio by the baseline's. Shared platform
67
- * noise (CPU contention, scheduler jitter) inflates both numerator and
68
- * denominator and cancels out; only `fn`-specific super-linear growth pushes
69
- * the normalized ratio past 1. Min across trials picks the cleanest sample.
70
- *
71
- * @param fn - The function to benchmark
72
- * @param buildInput - Builds an input string of approximately `n` units
73
- * @param startingN - Size parameter for the smallest input (default: 5000)
74
- */
75
- export function assertLinearScaling(fn, buildInput, startingN = 5000) {
76
- const input4x = buildInput(startingN * 4);
77
- const input8x = buildInput(startingN * 8);
78
- // Warmup both with the largest input so JIT compiles all code paths.
79
- fn(input8x);
80
- linearBaseline(input8x);
81
- const minTrials = 8;
82
- const minElapsedMs = 200;
83
- let bestRatio = Infinity;
84
- let totalElapsed = 0;
85
- let trials = 0;
86
- while (trials < minTrials || totalElapsed < minElapsedMs) {
87
- const startFn4 = performance.now();
88
- fn(input4x);
89
- const fnTime4 = performance.now() - startFn4;
90
- const startBase4 = performance.now();
91
- linearBaseline(input4x);
92
- const baseTime4 = performance.now() - startBase4;
93
- const startFn8 = performance.now();
94
- fn(input8x);
95
- const fnTime8 = performance.now() - startFn8;
96
- const startBase8 = performance.now();
97
- linearBaseline(input8x);
98
- const baseTime8 = performance.now() - startBase8;
99
- const fnRatio = (fnTime8 / input8x.length) / (fnTime4 / input4x.length);
100
- const baseRatio = (baseTime8 / input8x.length) / (baseTime4 / input4x.length);
101
- const ratio = fnRatio / baseRatio;
102
- bestRatio = Math.min(bestRatio, ratio);
103
- totalElapsed += fnTime4 + fnTime8 + baseTime4 + baseTime8;
104
- trials++;
105
- }
106
- // After baseline-normalization: linear ≈ 1, quadratic ≈ 2.
107
- expect(bestRatio).toBeLessThan(1.5);
108
- }
109
- //# sourceMappingURL=test-helpers.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"test-helpers.js","sourceRoot":"","sources":["../../src/tests/test-helpers.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,UAAU,MAAM,YAAY,CAAA;AAEnC;;;;GAIG;AACH,MAAM,SAAS,GAAG;IAChB,qBAAqB;IACrB,oCAAoC;IACpC,UAAU;IACV,4BAA4B;IAC5B,aAAa;IACb,eAAe;IACf,mBAAmB;IACnB,sBAAsB;IACtB,yBAAyB;IACzB,qBAAqB;IACrB,wBAAwB;IACxB,uBAAuB;IACvB,oBAAoB;IACpB,mBAAmB;IACnB,sCAAsC;IACtC,0BAA0B;IAC1B,mBAAmB;IACnB,uCAAuC;IACvC,0BAA0B;IAC1B,mBAAmB;CACpB,CAAA;AAED;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAAC,SAAiB,EAAE,OAAe,IAAI;IACtE,MAAM,MAAM,GAAG,UAAU,CAAC,IAAI,CAAC,CAAA;IAC/B,IAAI,MAAM,GAAG,EAAE,CAAA;IACf,OAAO,MAAM,CAAC,MAAM,GAAG,SAAS,EAAE,CAAC;QACjC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,GAAG,SAAS,CAAC,MAAM,CAAC,CAAA;QACrD,MAAM,IAAI,SAAS,CAAC,KAAK,CAAC,CAAA;IAC5B,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC;AAED;;;;;GAKG;AACH,MAAM,cAAc,GAAG,CAAC,CAAS,EAAU,EAAE,CAAC,CA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