Skip to content

Commit 08bfd13

Browse files
Remove B.prototype.run monkey-patch, use mitata defaults
Removes the unsafe monkey-patch of mitata's B.prototype.run that was injecting custom min_cpu_time and min_samples. mitata already handles warmup, statistics, and outlier detection natively — its defaults are sufficient for our use case. Co-authored-by: NullVoxPopuli <[email protected]>
1 parent df8ccc9 commit 08bfd13

1 file changed

Lines changed: 1 addition & 57 deletions

File tree

tests/parser.bench.mjs

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -15,63 +15,7 @@ import { createRequire } from 'node:module';
1515
import { readFileSync } from 'node:fs';
1616
import { fileURLToPath } from 'node:url';
1717
import { resolve } from 'node:path';
18-
import { run, bench, boxplot, summary, B, measure, flags } from 'mitata';
19-
20-
// ---------------------------------------------------------------------------
21-
// Increase mitata's per-benchmark timing for more stable results.
22-
//
23-
// mitata defaults to ~642 ms min CPU time and 12 min samples per benchmark.
24-
// We increase these to collect more samples and reduce variance from
25-
// transient system noise. The values are configurable via env vars.
26-
// ---------------------------------------------------------------------------
27-
28-
const BENCH_MIN_CPU_TIME = Number(process.env.BENCH_MIN_CPU_TIME) || 2_000_000_000; // 2 s in ns
29-
const BENCH_MIN_SAMPLES = Number(process.env.BENCH_MIN_SAMPLES) || 30;
30-
31-
const _origRun = B.prototype.run;
32-
B.prototype.run = async function (thrw = false) {
33-
// Only patch static benchmarks (no parametric args) — our use case
34-
if (Object.keys(this._args).length > 0) return _origRun.call(this, thrw);
35-
36-
const heap = await (async () => {
37-
try {
38-
const { getHeapStatistics } = await import('node:v8');
39-
getHeapStatistics(); // warm up / verify the API is available
40-
return () => {
41-
const m = getHeapStatistics();
42-
return m.used_heap_size + m.malloced_memory;
43-
};
44-
} catch {
45-
/* not available */
46-
}
47-
})();
48-
49-
const tune = {
50-
inner_gc: this._gc === 'inner',
51-
gc: !this._gc ? false : undefined,
52-
heap,
53-
min_cpu_time: BENCH_MIN_CPU_TIME,
54-
min_samples: BENCH_MIN_SAMPLES,
55-
};
56-
57-
let stats, error;
58-
try {
59-
stats = await measure(this.f, tune);
60-
} catch (err) {
61-
error = err;
62-
if (thrw) throw err;
63-
}
64-
65-
return {
66-
kind: 'static',
67-
args: this._args,
68-
alias: this._name,
69-
group: this._group,
70-
baseline: !!(this.flags & flags.baseline),
71-
runs: [{ stats, error, args: {}, name: this._name }],
72-
style: { highlight: this._highlight, compact: !!(this.flags & flags.compact) },
73-
};
74-
};
18+
import { run, bench, boxplot, summary } from 'mitata';
7519

7620
// ---------------------------------------------------------------------------
7721
// CLI args

0 commit comments

Comments
 (0)