Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hirestime

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hirestime - npm Package Compare versions

Comparing version 1.0.7 to 2.0.1

38

index.js

@@ -1,24 +0,32 @@

var S = 's';
var MS = 'ms';
var NS = 'ns';
var S = 's'
var MS = 'ms'
var NS = 'ns'
var round = number => Math.round(number * 100) / 100
function hirestime() {
var start = process.hrtime();
var start = process.hrtime()
return function (unit) {
var elapsed = process.hrtime(start);
return unit => {
var elapsed = process.hrtime(start)
var time;
if (unit === S) time = elapsed[0] + elapsed[1] / 1e9;
else if (unit === NS) time = elapsed[0] * 1e9 + elapsed[1];
else if (unit === MS || !unit || !time) time = elapsed[0] * 1e3 + elapsed[1] / 1e6;
if (!unit) unit = MS
return parseInt(time * 100, 10) / 100;
switch (unit) {
case S:
return round(elapsed[0] + elapsed[1] / 1e9)
case MS:
return round(elapsed[0] * 1e3 + elapsed[1] / 1e6)
case NS:
return round(elapsed[0] * 1e9 + elapsed[1])
}
}
}
hirestime.S = S;
hirestime.MS = MS;
hirestime.NS = NS;
hirestime.S = S
hirestime.MS = MS
hirestime.NS = NS
module.exports = hirestime;
module.exports = hirestime
{
"name": "hirestime",
"version": "1.0.7",
"version": "2.0.1",
"description": "thin wrapper around process.hrtime",

@@ -31,6 +31,9 @@ "main": "index.js",

"devDependencies": {
"chai": "3.4.1",
"hrtimemock": "1.0.1",
"mocha": "2.3.4"
"chai": "^3.5.0",
"hrtimemock": "^1.0.1",
"mocha": "^2.5.3"
},
"engines": {
"node": ">=4.0"
}
}

@@ -5,3 +5,3 @@ # hirestime [![Build Status](https://api.travis-ci.org/seriousManual/hirestime.png)](https://travis-ci.org/seriousmanual/hirestime)

[![NPM](https://nodei.co/npm-dl/hirestime.png?months=3)](https://nodei.co/npm/hirestime/)
[![NPM](https://nodei.co/npm-dl/hirestime.png?months=12)](https://nodei.co/npm/hirestime/)

@@ -31,24 +31,24 @@ hirestime is a thin wrapper around `process.hrtime()` that does the clumsy handling of the returned array for you.

````javascript
var hirestime = require('../');
var hirestime = require('../')
//startpoint of the time measurement
var getElapsed = hirestime();
var getElapsed = hirestime()
setTimeout(function() {
setTimeout(_ => {
//returns the elapsed milliseconds
console.log(getElapsed());
}, 1000);
console.log(getElapsed())
}, 1000)
````
````javascript
var hirestime = require('../');
var hirestime = require('../')
//startpoint of the time measurement
var getElapsed = hirestime();
var getElapsed = hirestime()
setTimeout(function() {
setTimeout(_ => {
//returns the elapsed seconds
console.log(getElapsed(hirestime.S));
}, 1000);
console.log(getElapsed(hirestime.S))
}, 1000)
````

@@ -1,42 +0,35 @@

var expect = require('chai').expect;
var hrtimeMock = require('hrtimemock');
var expect = require('chai').expect
var hrtimeMock = require('hrtimemock')
var hirestime = require('../');
var hirestime = require('../')
describe('hirestime', function() {
it('should return an approximate number of elapsed time in milliseconds (no unit given)', function() {
hrtimeMock(1100);
var getElapsed = hirestime();
it('should return an approximate number of elapsed time in milliseconds (no unit given)', () => {
hrtimeMock(1119)
var getElapsed = hirestime()
expect(getElapsed()).to.equal(1100);
});
expect(getElapsed()).to.equal(1119)
})
it('should return an approximate number of elapsed time in seconds (seconds unit)', function() {
hrtimeMock(1100);
var getElapsed = hirestime();
it('should return an approximate number of elapsed time in seconds (seconds unit)', () => {
hrtimeMock(1119)
var getElapsed = hirestime()
expect(getElapsed(hirestime.S)).to.equal(1.1);
});
expect(getElapsed(hirestime.S)).to.equal(1.12)
})
it('should return an approximate number of elapsed time in milliseconds (milliseconds unit)', function() {
hrtimeMock(1100);
var getElapsed = hirestime();
it('should return an approximate number of elapsed time in milliseconds (milliseconds unit)', () => {
hrtimeMock(1119)
var getElapsed = hirestime()
expect(getElapsed(hirestime.MS)).to.equal(1100);
});
expect(getElapsed(hirestime.MS)).to.equal(1119)
})
it('should return an approximate number of elapsed time in nanoseconds (nanoseconds unit)', function() {
hrtimeMock(1100);
var getElapsed = hirestime();
it('should return an approximate number of elapsed time in nanoseconds (nanoseconds unit)', () => {
hrtimeMock(1119)
var getElapsed = hirestime()
expect(getElapsed(hirestime.NS)).to.equal(1100000000);
});
it('should return an approximate number of elapsed time in milliseconds (unknown unit)', function() {
hrtimeMock(1100);
var getElapsed = hirestime();
expect(getElapsed('foo')).to.equal(1100);
});
});
expect(getElapsed(hirestime.NS)).to.equal(1119000000)
})
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc