Browse Source

benchmark: check for time precision in common.js

Some benchmark tests are failing intermittently, possibly due to
hrtime() imprecision on particular hosts. This change will confirm or
refute that as the root cause the next time the test fails on CI. Either
way, it's a valid check.

PR-URL: https://github.com/nodejs/node/pull/12934
Ref: https://github.com/nodejs/node/issues/12497
Ref: https://github.com/nodejs/node/issues/12433
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
v6
Rich Trott 8 years ago
parent
commit
a82e0e6f36
  1. 3
      benchmark/common.js

3
benchmark/common.js

@ -196,6 +196,9 @@ Benchmark.prototype.end = function(operations) {
if (!process.env.NODEJS_BENCHMARK_ZERO_ALLOWED && operations <= 0) {
throw new Error('called end() with operation count <= 0');
}
if (elapsed[0] === 0 && elapsed[1] === 0) {
throw new Error('insufficient time precision for short benchmark');
}
const time = elapsed[0] + elapsed[1] / 1e9;
const rate = operations / time;

Loading…
Cancel
Save