https://github.com/spazmodius/now
Faster now() for Node.js
https://github.com/spazmodius/now
module node
Last synced: about 2 months ago
JSON representation
Faster now() for Node.js
- Host: GitHub
- URL: https://github.com/spazmodius/now
- Owner: spazmodius
- Created: 2019-01-26T04:16:29.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-05-28T20:45:40.000Z (about 5 years ago)
- Last Synced: 2025-01-23T11:23:42.307Z (over 1 year ago)
- Topics: module, node
- Language: JavaScript
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Spaz's Faster now()
***Faster now() for Node.js***
Let's be clear: `Date.now()` is not "slow".
On Spaz's c.2018 laptop it returns the current time in about 80 nanoseconds (yes, _nano_; 80 billionths-with-a-B of a second.)
But, if you like speed like Spaz likes speed, it turns out that, using Node's [`process.hrtime()`](https://nodejs.org/api/process.html#process_process_hrtime_time), we can calculate the current time in about _half the nanos!_
Crazy.
## Installation and Usage
`npm install spazmodius/now`
```js
const now = require('@spazmodius/now')
console.log('The current time is', now(), Date.now())
```
## now()
Returns the number of milliseconds since the UNIX epoch.
This is a drop-in replacement for [`Date.now()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/now).