Permalink
Browse files

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: #12934
Ref: #12497
Ref: #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 9, 2017
1 parent 6f449db commit a82e0e6f361ac0923539d2c47586159fff9c6573
Showing with 3 additions and 0 deletions.
  1. +3 −0 benchmark/common.js
View
@@ -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;

0 comments on commit a82e0e6

Please sign in to comment.