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.

PR-URL: nodejs#12934
Ref: nodejs#12497
Ref: nodejs#12433
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
Trott committed May 11, 2017
1 parent 6f449db commit a82e0e6
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 a82e0e6

Please sign in to comment.