mirror of
https://github.com/nodejs/node.git
synced 2026-10-28 18:25:13 +08:00
Most node:bench tests record a sample with `b.start();
process.hrtime.bigint(); b.end(1)`, counting on the extra clock read to
make end() see a later timestamp than start(). On a debian12-x64 CI
host the monotonic clock is coarse enough that all three reads returned
the same value, so end() threw ERR_INVALID_STATE ("insufficient clock
precision for benchmark sample") and test-bench-harness-errors failed;
every test using the idiom can fail the same way there.
Add test/common/bench.js with completeSample(), which spins until
process.hrtime.bigint() moves between start() and end(), and use it at
all of those sites, bench-runner fixtures included.
Signed-off-by: Shelley Vohr <shelley.vohr@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/65780
Fixes: https://github.com/nodejs/node/issues/64226
Refs: https://github.com/nodejs/node/issues/59146
Refs: https://github.com/nodejs/node/issues/54534
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
14 lines
438 B
JavaScript
14 lines
438 B
JavaScript
'use strict';
|
|
|
|
// Records a sample with start()/end() and at least one hrtime tick in
|
|
// between, so its duration is non-zero even on hosts with a coarse clock.
|
|
function completeSample(b, operations = 1, options = undefined) {
|
|
b.start();
|
|
const started = process.hrtime.bigint();
|
|
let now = started;
|
|
while (now === started) now = process.hrtime.bigint();
|
|
return b.end(operations, options);
|
|
}
|
|
|
|
module.exports = { completeSample };
|