From fce0126c13bee6109a71f19e654d13633692ef11 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Sun, 5 Mar 2017 01:23:16 -0800 Subject: [PATCH] util: refactor hrtime usage. --- lib/blockchain/chain.js | 5 ++--- lib/utils/util.js | 9 ++++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/blockchain/chain.js b/lib/blockchain/chain.js index 10892250..aa8a9d42 100644 --- a/lib/blockchain/chain.js +++ b/lib/blockchain/chain.js @@ -1342,7 +1342,7 @@ Chain.prototype.mark = function mark() { */ Chain.prototype.finish = function finish(block, entry) { - var elapsed, time; + var elapsed; // Keep track of total blocks handled. this.total += 1; @@ -1355,7 +1355,6 @@ Chain.prototype.finish = function finish(block, entry) { this.logger.memory(); elapsed = util.hrtime(this.startTime); - time = elapsed[0] * 1000 + elapsed[1] / 1e6; this.logger.info( 'Block %s (%d) added to chain (size=%d txs=%d time=%d).', @@ -1363,7 +1362,7 @@ Chain.prototype.finish = function finish(block, entry) { entry.height, block.getSize(), block.txs.length, - time); + elapsed); if (this.db.coinCache.capacity > 0) { this.logger.debug('Coin Cache: size=%dmb, items=%d.', diff --git a/lib/utils/util.js b/lib/utils/util.js index b438d73e..50cc8f51 100644 --- a/lib/utils/util.js +++ b/lib/utils/util.js @@ -137,21 +137,24 @@ util.isBase58 = function isBase58(obj) { */ util.hrtime = function hrtime(time) { - var now, ms, sec; + var now, ms, sec, elapsed; if (util.isBrowser) { now = util.ms(); if (time) { time = time[0] * 1000 + time[1] / 1e6; now -= time; + return now; } ms = now % 1000; sec = (now - ms) / 1000; return [sec, ms * 1e6]; } - if (time) - return process.hrtime(time); + if (time) { + elapsed = process.hrtime(time); + return elapsed[0] * 1000 + elapsed[1] / 1e6; + } return process.hrtime(); };