Skip to content

Commit 939f579

Browse files
committed
bench: stabilize prefix-source getPrefix() and original() cases
Both accessors are one-line property reads. At 500 iterations the work completes in microseconds, putting the measurement at the timer-resolution / JIT-tier-up noise floor; with no use of the return value the optimizer is also free to strength-reduce the loop. Raise the inner iteration count to 50,000 and consume the return value into a sink so V8 cannot elide the load. RME drops from unstable to ~1.2%.
1 parent 9788e55 commit 939f579

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

benchmark/cases/prefix-source/index.bench.mjs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,19 @@ export default function register(bench) {
2929

3030
bench.add("prefix-source: getPrefix()", () => {
3131
const ps = new sources.PrefixSource("\t", fixtureCode);
32-
for (let i = 0; i < 500; i++) ps.getPrefix();
32+
let sink = 0;
33+
for (let i = 0; i < 50_000; i++) sink ^= ps.getPrefix().length;
34+
if (sink === -1) throw new Error("unreachable");
3335
});
3436

3537
bench.add("prefix-source: original()", () => {
3638
const ps = new sources.PrefixSource(
3739
"\t",
3840
new sources.RawSource(fixtureCode),
3941
);
40-
for (let i = 0; i < 500; i++) ps.original();
42+
let sink = 0;
43+
for (let i = 0; i < 50_000; i++) sink ^= ps.original() === ps ? 1 : 0;
44+
if (sink === -1) throw new Error("unreachable");
4145
});
4246

4347
bench.add("prefix-source: source() (RawSource child)", () => {

0 commit comments

Comments
 (0)