Comparing version 0.2.2 to 0.2.3
@@ -11,3 +11,8 @@ var S = 'seconds'; | ||
return recalc(elapsed[0] * 1e3 + elapsed[1] / 1e6, unit); | ||
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; | ||
return parseInt(time * 100, 10) / 100; | ||
} | ||
@@ -14,0 +19,0 @@ } |
{ | ||
"name": "hirestime", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"description": "thin wrapper around process.hrtime", | ||
@@ -26,4 +26,4 @@ "main": "index.js", | ||
"chai": "~1.8.1", | ||
"hrtimemock": "0.0.1" | ||
"hrtimemock": "0.0.2" | ||
} | ||
} |
@@ -9,35 +9,35 @@ var expect = require('chai').expect; | ||
it('should return an approximate number of elapsed time in milliseconds (no unit given)', function() { | ||
hrtimeMock(100); | ||
hrtimeMock(1100); | ||
var getElapsed = hirestime(); | ||
expect(getElapsed()).to.equal(100); | ||
expect(getElapsed()).to.equal(1100); | ||
}); | ||
it('should return an approximate number of elapsed time in seconds (seconds unit)', function() { | ||
hrtimeMock(100); | ||
hrtimeMock(1100); | ||
var getElapsed = hirestime(); | ||
expect(getElapsed(hirestime.S)).to.equal(0.1); | ||
expect(getElapsed(hirestime.S)).to.equal(1.1); | ||
}); | ||
it('should return an approximate number of elapsed time in seconds (milliseconds unit)', function() { | ||
hrtimeMock(100); | ||
it('should return an approximate number of elapsed time in milliseconds (milliseconds unit)', function() { | ||
hrtimeMock(1100); | ||
var getElapsed = hirestime(); | ||
expect(getElapsed(hirestime.MS)).to.equal(100); | ||
expect(getElapsed(hirestime.MS)).to.equal(1100); | ||
}); | ||
it('should return an approximate number of elapsed time in seconds (nanoseconds unit)', function() { | ||
hrtimeMock(100); | ||
it('should return an approximate number of elapsed time in nanoseconds (nanoseconds unit)', function() { | ||
hrtimeMock(1100); | ||
var getElapsed = hirestime(); | ||
expect(getElapsed(hirestime.NS)).to.equal(100000); | ||
expect(getElapsed(hirestime.NS)).to.equal(1100000000); | ||
}); | ||
it('should return an approximate number of elapsed time in seconds (unknown unit)', function() { | ||
hrtimeMock(100); | ||
it('should return an approximate number of elapsed time in milliseconds (unknown unit)', function() { | ||
hrtimeMock(1100); | ||
var getElapsed = hirestime(); | ||
expect(getElapsed('foo')).to.equal(100); | ||
expect(getElapsed('foo')).to.equal(1100); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5538
60