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 3.1.1 to 3.2.0

test.js

58

index.js

@@ -9,42 +9,52 @@ 'use strict'

function formatFromMs(value, unit) {
if (!unit || unit === MS) {
return round(value)
}
if (unit === S) {
return round(value / 1e3)
}
return round(value * 1e6)
}
function hirestimeNode() {
const start = process.hrtime()
return unit => {
let elapsed = process.hrtime(start)
let value = elapsed[0] * 1e3 + elapsed[1] / 1e6
switch (unit) {
case S:
return round(elapsed[0] + elapsed[1] / 1e9)
case NS:
return round(elapsed[0] * 1e9 + elapsed[1])
}
return round(elapsed[0] * 1e3 + elapsed[1] / 1e6)
return formatFromMs(value, unit);
}
}
function hiresTimeBrowser() {
function hiresTimeBrowserPerformance() {
const start = window.performance.now()
return unit => formatFromMs(window.performance.now() - start, unit)
}
function hiresTimeBrowserDate() {
const start = Date.now()
return unit => formatFromMs(Date.now() - start, unit)
}
return unit => {
var elapsed = Date.now() - start
module.exports = (() => {
if (typeof process != "undefined" && process.hrtime) {
return hirestimeNode
}
switch (unit) {
case S:
return round(elapsed / 1e3)
if (typeof window != "undefined" && window.performance) {
return hiresTimeBrowserDate
}
case NS:
return round(elapsed * 1e6)
}
return hiresTimeBrowserDate
})()
return elapsed
}
}
module.exports.node = hirestimeNode
module.exports.browserDate = hiresTimeBrowserDate
module.exports.hiresTimeBrowserPerformance = hiresTimeBrowserPerformance
module.exports = process.hrtime ? hirestimeNode : hiresTimeBrowser
module.exports.S = S
module.exports.MS = MS
module.exports.NS = NS
{
"name": "hirestime",
"version": "3.1.1",
"version": "3.2.0",
"description": "thin wrapper around process.hrtime",
"main": "index.js",
"scripts": {
"test": "./node_modules/.bin/mocha tests"
"test": "mocha test.js"
},

@@ -33,3 +33,3 @@ "repository": {

"hrtimemock": "^2.0.0",
"mocha": "^3.0.0",
"mocha": "^3.4.0",
"sinon": "^1.17.6"

@@ -36,0 +36,0 @@ },

@@ -1,2 +0,2 @@

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

@@ -7,4 +7,4 @@ [![NPM](https://nodei.co/npm/hirestime.png)](https://nodei.co/npm/hirestime/)

`hirestime` is a thin wrapper around `process.hrtime()` that does the clumsy handling of the returned array for you.
Also works in the browser.
`hirestime` is a thin wrapper around the common time measuring APIs (node and the browser).
Uses `process.hrtime()` on node, the [performance API](https://developer.mozilla.org/de/docs/Web/API/Performance/now) in the browser and falls back to `Date` if neither is available.

@@ -27,3 +27,3 @@ ## Installation

* `hirestime.S` elapsed time in seconds
* `hirestime.MS` elapsed time in milliseoncds
* `hirestime.MS` elapsed time in milliseconds
* `hirestime.NS` elapsed time in nanoseconds

@@ -30,0 +30,0 @@

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