From a82e0e6f361ac0923539d2c47586159fff9c6573 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Tue, 9 May 2017 14:07:51 -0700 Subject: [PATCH] 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 Reviewed-By: Joyee Cheung Reviewed-By: James M Snell --- benchmark/common.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/benchmark/common.js b/benchmark/common.js index fc47a3ce025..32a16974225 100644 --- a/benchmark/common.js +++ b/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;