relative-microtime
Advanced tools
Comparing version 1.0.0 to 2.0.0
16
index.js
'use strict' | ||
const nanoStart = process.hrtime() | ||
const microStart = Date.now() * 1000 | ||
module.exports = function sync () { | ||
const nanoStart = process.hrtime() | ||
const microStart = Date.now() * 1000 | ||
module.exports = function microtime () { | ||
const diff = process.hrtime(nanoStart) | ||
const microRemainder = diff[1] / 1000 | 0 // Use bitwise OR to remove the decimals | ||
const microDelta = diff[0] * 1e6 + microRemainder | ||
return microStart + microDelta | ||
return function microtime () { | ||
const diff = process.hrtime(nanoStart) | ||
const microRemainder = diff[1] / 1000 | 0 // Use bitwise OR to remove the decimals | ||
const microDelta = diff[0] * 1e6 + microRemainder | ||
return microStart + microDelta | ||
} | ||
} |
{ | ||
"name": "relative-microtime", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"description": "Get the number of microseconds elapsed since January 1, 1970 00:00:00 UTC without fear of clock drift", | ||
@@ -37,5 +37,5 @@ "main": "index.js", | ||
"coordinates": [ | ||
55.778268, | ||
12.593064 | ||
55.778279, | ||
12.593066 | ||
] | ||
} |
@@ -6,5 +6,5 @@ # relative-microtime | ||
Note: The returned number of microseconds are locked relative to the | ||
start time of the process and is therefore not subject to clock drift. | ||
This is contrary to how `Date.now()` operates, whos return value (in | ||
Note: The returned number of microseconds are locked relative to a | ||
specific time and is therefore not subject to clock drift. This is | ||
contrary to how `Date.now()` operates, whos return value (in | ||
milliseconds) is always based on the system clock. | ||
@@ -25,6 +25,6 @@ | ||
```js | ||
const microtime = require('relative-microtime') | ||
const timer = require('relative-microtime')() | ||
const milli = Date.now() | ||
const micro = microtime() | ||
const micro = timer() | ||
@@ -39,4 +39,12 @@ console.log(milli) // 1537446194859 | ||
### `microtime()` | ||
### `timer = microtime()` | ||
Sync the microtime clock to the UTC wall clock. | ||
Returns a `timer` function synced with the UTC time when `microtime()` | ||
was called. Any clock drift that happens after the call to `microtime()` | ||
will not influence the returned `timer`. | ||
### `timer()` | ||
Returns a `Number` representing the microseconds elapsed since the UNIX | ||
@@ -43,0 +51,0 @@ epoch. |
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
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
3778
11
53
0