Files
node/test/parallel/test-bench-auto-run.js
T
James M Snell dff7a160fe lib: put node:bench behind an --experimental-bench flag
Signed-off-by: James M Snell <jasnell@gmail.com>
Assisted-by: Opencode
PR-URL: https://github.com/nodejs/node/pull/65920
Reviewed-By: Jordan Harband <ljharb@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
Reviewed-By: Xuguang Mei <meixuguang@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
2026-09-12 08:29:12 +00:00

28 lines
869 B
JavaScript

// Flags: --experimental-bench --no-warnings
'use strict';
const common = require('../common');
const assert = require('assert');
const { spawnSync } = require('child_process');
const { bench } = require('node:bench');
const child = spawnSync(process.execPath, [
'--no-warnings',
'--experimental-bench',
'-e',
'require("node:bench").bench("failure", () => { throw new Error(); })',
]);
assert.strictEqual(child.status, 1);
const completion = bench('automatic execution', common.mustCall((b) => {
b.record({ duration_ns: 1n, operations: 1 });
}, 30));
completion.then(common.mustCall((result) => {
assert.strictEqual(result.name, 'automatic execution');
assert.strictEqual(result.samples.length, 30);
assert.strictEqual(result.error, undefined);
assert.strictEqual(result.skip, undefined);
assert.strictEqual(result.summary.mean > 0, true);
}));