mirror of
https://github.com/nodejs/node.git
synced 2026-11-09 15:11:11 -05:00
Signed-off-by: James M Snell <jasnell@gmail.com> Assisted-by: Opencode PR-URL: https://github.com/nodejs/node/pull/65606 Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
103 lines
3.7 KiB
JavaScript
103 lines
3.7 KiB
JavaScript
// Flags: --no-warnings
|
|
'use strict';
|
|
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const { createRunner } = require('node:bench');
|
|
|
|
const runner = createRunner({ yieldBetweenSamples: false });
|
|
|
|
runner.bench('done during warmup', { samples: 1, warmup: 1 }, (b) => {
|
|
b.start();
|
|
process.hrtime.bigint();
|
|
b.end(1);
|
|
b.done();
|
|
});
|
|
runner.bench('invalid record', { samples: 1 }, (b) => b.record(null));
|
|
runner.bench('invalid duration type', { samples: 1 }, (b) => b.record({
|
|
duration_ns: 1,
|
|
operations: 1,
|
|
}));
|
|
runner.bench('invalid duration value', { samples: 1 }, (b) => b.record({
|
|
duration_ns: 0n,
|
|
operations: 1,
|
|
}));
|
|
runner.bench('duration too large', { samples: 1 }, (b) => b.record({
|
|
duration_ns: 9_007_199_254_740_992n,
|
|
operations: 1,
|
|
}));
|
|
runner.bench('invalid operations', { samples: 1 }, (b) => b.record({
|
|
duration_ns: 1n,
|
|
operations: 0,
|
|
}));
|
|
runner.bench('mixed timing', { samples: 1 }, (b) => {
|
|
b.start();
|
|
b.record({ duration_ns: 1n, operations: 1 });
|
|
});
|
|
runner.bench('start after record', { samples: 1 }, (b) => {
|
|
b.record({ duration_ns: 1n, operations: 1 });
|
|
b.start();
|
|
});
|
|
runner.bench('end after record', { samples: 1 }, (b) => {
|
|
b.record({ duration_ns: 1n, operations: 1 });
|
|
b.end(1);
|
|
});
|
|
runner.bench('duplicate record', { samples: 1 }, (b) => {
|
|
b.record({ duration_ns: 1n, operations: 1 });
|
|
b.record({ duration_ns: 1n, operations: 1 });
|
|
});
|
|
runner.bench('reentrant record', { samples: 1 }, (b) => {
|
|
const sample = { duration_ns: 1n };
|
|
Object.defineProperty(sample, 'operations', {
|
|
get() {
|
|
b.record({ duration_ns: 1n, operations: 1 });
|
|
return 1;
|
|
},
|
|
});
|
|
b.record(sample);
|
|
});
|
|
runner.bench('uncloneable detail', { samples: 1 }, (b) => {
|
|
b.record({ duration_ns: 1n, operations: 1, detail: () => {} });
|
|
});
|
|
runner.bench('caught contract violation', { samples: 1 },
|
|
common.mustCall((b) => {
|
|
b.start();
|
|
assert.throws(() => b.start(), { code: 'ERR_INVALID_STATE' });
|
|
b.end(1);
|
|
}));
|
|
|
|
(async () => {
|
|
const records = await runner.run().toArray();
|
|
const completions = records
|
|
.filter(({ type }) => type === 'bench:complete')
|
|
.map(({ data }) => data);
|
|
const byName = new Map(completions.map((result) => [result.name, result]));
|
|
|
|
assert.strictEqual(byName.get('done during warmup').error.code,
|
|
'ERR_INVALID_STATE');
|
|
assert.strictEqual(byName.get('invalid record').error.code,
|
|
'ERR_INVALID_ARG_TYPE');
|
|
assert.strictEqual(byName.get('invalid duration type').error.code,
|
|
'ERR_INVALID_ARG_TYPE');
|
|
assert.strictEqual(byName.get('invalid duration value').error.code,
|
|
'ERR_OUT_OF_RANGE');
|
|
assert.strictEqual(byName.get('duration too large').error.code,
|
|
'ERR_OUT_OF_RANGE');
|
|
assert.strictEqual(byName.get('invalid operations').error.code,
|
|
'ERR_OUT_OF_RANGE');
|
|
assert.strictEqual(byName.get('mixed timing').error.code,
|
|
'ERR_INVALID_STATE');
|
|
assert.strictEqual(byName.get('start after record').error.code,
|
|
'ERR_INVALID_STATE');
|
|
assert.strictEqual(byName.get('end after record').error.code,
|
|
'ERR_INVALID_STATE');
|
|
assert.strictEqual(byName.get('duplicate record').error.code,
|
|
'ERR_INVALID_STATE');
|
|
assert.strictEqual(byName.get('reentrant record').error.code,
|
|
'ERR_INVALID_STATE');
|
|
assert.strictEqual(byName.get('uncloneable detail').error.name,
|
|
'DataCloneError');
|
|
assert.match(byName.get('caught contract violation').error.message,
|
|
/violated the start\(\)\/end\(\) contract/);
|
|
})().then(common.mustCall());
|