Skip to content

Commit

Permalink
benchmark: check for time precision in common.js
Browse files Browse the repository at this point in the history
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.

Refs: nodejs#12497
Refs: nodejs#12433
  • Loading branch information
Trott committed May 9, 2017
1 parent faf6654 commit 90a4a43
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions benchmark/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 90a4a43

Please sign in to comment.