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 2.0.1 to 2.1.0

30

index.js

@@ -7,3 +7,3 @@ var S = 's'

function hirestime() {
function hirestimeNode() {
var start = process.hrtime()

@@ -29,6 +29,26 @@

hirestime.S = S
hirestime.MS = MS
hirestime.NS = NS
function hiresTimeBrowser() {
var start = Date.now()
module.exports = hirestime
return unit => {
var elapsed = Date.now() - start
if (!unit) unit = MS
switch (unit) {
case S:
return round(elapsed / 1e3)
case NS:
return round(elapsed * 1e6)
}
return elapsed
}
}
module.exports = process.hrtime ? hirestimeNode : hiresTimeBrowser
module.exports.S = S
module.exports.MS = MS
module.exports.NS = NS

5

package.json
{
"name": "hirestime",
"version": "2.0.1",
"version": "2.1.0",
"description": "thin wrapper around process.hrtime",

@@ -33,3 +33,4 @@ "main": "index.js",

"hrtimemock": "^1.0.1",
"mocha": "^2.5.3"
"mocha": "^3.0.0",
"sinon": "^1.17.6"
},

@@ -36,0 +37,0 @@ "engines": {

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

hirestime is a thin wrapper around `process.hrtime()` that does the clumsy handling of the returned array for you.
Since version 2.1 this module also works in the browser.

@@ -10,0 +11,0 @@ ## Installation

@@ -0,35 +1,80 @@

var sinon = require('sinon')
var expect = require('chai').expect
var hrtimeMock = require('hrtimemock')
var hirestime = require('../')
describe('hirestime', function() {
it('should return an approximate number of elapsed time in milliseconds (no unit given)', () => {
hrtimeMock(1119)
var getElapsed = hirestime()
describe('node', () => {
var hirestime
before(() => hirestime = require('../'))
after(() => {
delete require.cache[require.resolve('../')]
})
expect(getElapsed()).to.equal(1119)
})
it('should return an approximate number of elapsed time in milliseconds (no unit given)', () => {
hrtimeMock(1119)
var getElapsed = hirestime()
it('should return an approximate number of elapsed time in seconds (seconds unit)', () => {
hrtimeMock(1119)
var getElapsed = hirestime()
expect(getElapsed()).to.equal(1119)
})
expect(getElapsed(hirestime.S)).to.equal(1.12)
})
it('should return an approximate number of elapsed time in seconds (seconds unit)', () => {
hrtimeMock(1119)
var getElapsed = hirestime()
it('should return an approximate number of elapsed time in milliseconds (milliseconds unit)', () => {
hrtimeMock(1119)
var getElapsed = hirestime()
expect(getElapsed(hirestime.S)).to.equal(1.12)
})
expect(getElapsed(hirestime.MS)).to.equal(1119)
it('should return an approximate number of elapsed time in milliseconds (milliseconds unit)', () => {
hrtimeMock(1119)
var getElapsed = hirestime()
expect(getElapsed(hirestime.MS)).to.equal(1119)
})
it('should return an approximate number of elapsed time in nanoseconds (nanoseconds unit)', () => {
hrtimeMock(1119)
var getElapsed = hirestime()
expect(getElapsed(hirestime.NS)).to.equal(1119000000)
})
})
it('should return an approximate number of elapsed time in nanoseconds (nanoseconds unit)', () => {
hrtimeMock(1119)
var getElapsed = hirestime()
describe('browser', () => {
var hirestime
var tmpHirestime = process.hrtime
var clock
before(() => {
tmpHirestime = process.hrtime
process.hrtime = null
clock = sinon.useFakeTimers()
expect(getElapsed(hirestime.NS)).to.equal(1119000000)
hirestime = require('../')
})
after(() => process.hrtime = tmpHirestime)
it('should return an approximate number of elapsed time in milliseconds (no unit given)', () => {
var getElapsed = hirestime()
clock.tick(1119)
expect(getElapsed()).to.equal(1119)
})
it('should return an approximate number of elapsed time in seconds (seconds unit)', () => {
var getElapsed = hirestime()
clock.tick(1119)
expect(getElapsed(hirestime.S)).to.equal(1.12)
})
it('should return an approximate number of elapsed time in milliseconds (milliseconds unit)', () => {
var getElapsed = hirestime()
clock.tick(1119)
expect(getElapsed(hirestime.MS)).to.equal(1119)
})
it('should return an approximate number of elapsed time in nanoseconds (nanoseconds unit)', () => {
var getElapsed = hirestime()
clock.tick(1119)
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