util: refactor hrtime usage.

This commit is contained in:
Christopher Jeffrey 2017-03-05 01:23:16 -08:00
parent a2fd9b35c6
commit fce0126c13
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 8 additions and 6 deletions

View File

@ -1342,7 +1342,7 @@ Chain.prototype.mark = function mark() {
*/ */
Chain.prototype.finish = function finish(block, entry) { Chain.prototype.finish = function finish(block, entry) {
var elapsed, time; var elapsed;
// Keep track of total blocks handled. // Keep track of total blocks handled.
this.total += 1; this.total += 1;
@ -1355,7 +1355,6 @@ Chain.prototype.finish = function finish(block, entry) {
this.logger.memory(); this.logger.memory();
elapsed = util.hrtime(this.startTime); elapsed = util.hrtime(this.startTime);
time = elapsed[0] * 1000 + elapsed[1] / 1e6;
this.logger.info( this.logger.info(
'Block %s (%d) added to chain (size=%d txs=%d time=%d).', '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, entry.height,
block.getSize(), block.getSize(),
block.txs.length, block.txs.length,
time); elapsed);
if (this.db.coinCache.capacity > 0) { if (this.db.coinCache.capacity > 0) {
this.logger.debug('Coin Cache: size=%dmb, items=%d.', this.logger.debug('Coin Cache: size=%dmb, items=%d.',

View File

@ -137,21 +137,24 @@ util.isBase58 = function isBase58(obj) {
*/ */
util.hrtime = function hrtime(time) { util.hrtime = function hrtime(time) {
var now, ms, sec; var now, ms, sec, elapsed;
if (util.isBrowser) { if (util.isBrowser) {
now = util.ms(); now = util.ms();
if (time) { if (time) {
time = time[0] * 1000 + time[1] / 1e6; time = time[0] * 1000 + time[1] / 1e6;
now -= time; now -= time;
return now;
} }
ms = now % 1000; ms = now % 1000;
sec = (now - ms) / 1000; sec = (now - ms) / 1000;
return [sec, ms * 1e6]; return [sec, ms * 1e6];
} }
if (time) if (time) {
return process.hrtime(time); elapsed = process.hrtime(time);
return elapsed[0] * 1000 + elapsed[1] / 1e6;
}
return process.hrtime(); return process.hrtime();
}; };