Files
node/test/parallel/test-bench-validation.js
RafaelGSS 299f76cb73 lib: default node:bench warmup to 10 invocations
Signed-off-by: RafaelGSS <rafael.nunu@hotmail.com>
PR-URL: https://github.com/nodejs/node/pull/66536
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Bryan English <bryan@bryanenglish.com>
2026-10-07 15:38:44 -03:00

81 lines
3.0 KiB
JavaScript

// Flags: --experimental-bench --no-warnings
'use strict';
const common = require('../common');
const { completeSample } = require('../common/bench');
const assert = require('assert');
const { bench, createRunner, run } = require('node:bench');
const noop = () => {};
let functionOverloadCalls = 0;
let objectOverloadCalls = 0;
function functionOverload(b) {
functionOverloadCalls++;
completeSample(b);
b.done();
}
function objectOverload(b) {
objectOverloadCalls++;
completeSample(b);
}
assert.throws(() => bench('', noop), { code: 'ERR_INVALID_ARG_VALUE' });
assert.throws(() => bench('name', null), { code: 'ERR_INVALID_ARG_TYPE' });
assert.throws(() => bench('name', { samples: 0 }, noop),
{ code: 'ERR_OUT_OF_RANGE' });
assert.throws(() => bench('name', { warmup: -1 }, noop),
{ code: 'ERR_OUT_OF_RANGE' });
assert.throws(() => bench('name', { timeout: -1 }, noop),
{ code: 'ERR_OUT_OF_RANGE' });
assert.throws(() => bench('name', { signal: {} }, noop),
{ code: 'ERR_INVALID_ARG_TYPE' });
assert.throws(() => bench('name', { diagnosticChannels: 'channel' }, noop),
{ code: 'ERR_INVALID_ARG_TYPE' });
assert.throws(() => bench('name', { diagnosticChannels: [1] }, noop),
{ code: 'ERR_INVALID_ARG_TYPE' });
assert.throws(() => bench('name', { tags: 'fast' }, noop),
{ code: 'ERR_INVALID_ARG_TYPE' });
assert.throws(() => bench('name', { tags: [''] }, noop),
{ code: 'ERR_INVALID_ARG_VALUE' });
assert.throws(() => bench('name', { params: { value: null } }, noop),
{ code: 'ERR_INVALID_ARG_TYPE' });
assert.throws(() => bench('name', { params: { value: NaN } }, noop),
{ code: 'ERR_OUT_OF_RANGE' });
assert.throws(() => bench('name', { only: 'yes' }, noop),
{ code: 'ERR_INVALID_ARG_TYPE' });
assert.throws(() => bench('name', { skip: 1 }, noop),
{ code: 'ERR_INVALID_ARG_TYPE' });
assert.throws(() => run({ namePattern: 1 }),
{ code: 'ERR_INVALID_ARG_TYPE' });
assert.throws(() => run({ samples: 0 }),
{ code: 'ERR_OUT_OF_RANGE' });
assert.throws(() => run({ warmup: -1 }),
{ code: 'ERR_OUT_OF_RANGE' });
assert.throws(() => run({ yieldBetweenSamples: 1 }),
{ code: 'ERR_INVALID_ARG_TYPE' });
assert.throws(() => createRunner(null),
{ code: 'ERR_INVALID_ARG_TYPE' });
assert.throws(() => createRunner({ yieldBetweenSamples: 1 }),
{ code: 'ERR_INVALID_ARG_TYPE' });
assert.throws(() => createRunner({ yieldBetweenSamples: null }),
{ code: 'ERR_INVALID_ARG_TYPE' });
bench(functionOverload);
bench({ samples: 1 }, objectOverload);
bench('valid', { samples: 1 }, (b) => {
completeSample(b);
});
const stream = run({ warmup: 0 });
stream.on('bench:start', common.mustCall(() => {
assert.throws(() => bench('late', noop), { code: 'ERR_INVALID_STATE' });
}, 3));
stream.on('end', common.mustCall(() => {
assert.strictEqual(functionOverloadCalls, 1);
assert.strictEqual(objectOverloadCalls, 1);
}));
stream.resume();