https://github.com/dnlup/hrtime-utils
A small collection of useful functions to work with Node.js `process.hrtime` values
https://github.com/dnlup/hrtime-utils
hrtime hrtime-utils node nodejs process
Last synced: about 1 year ago
JSON representation
A small collection of useful functions to work with Node.js `process.hrtime` values
- Host: GitHub
- URL: https://github.com/dnlup/hrtime-utils
- Owner: dnlup
- License: isc
- Created: 2020-03-26T11:42:59.000Z (about 6 years ago)
- Default Branch: next
- Last Pushed: 2023-01-16T11:02:53.000Z (over 3 years ago)
- Last Synced: 2025-03-17T22:08:15.831Z (about 1 year ago)
- Topics: hrtime, hrtime-utils, node, nodejs, process
- Language: JavaScript
- Homepage:
- Size: 873 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 18
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# hrtime-utils
[](https://badge.fury.io/js/%40dnlup%2Fhrtime-utils)

[](https://codecov.io/gh/dnlup/hrtime-utils)
[](https://snyk.io/test/github/dnlup/hrtime-utils?targetFile=package.json)
> A small collection of useful functions to work with Node.js [`process.hrtime`](https://nodejs.org/docs/latest-v12.x/api/process.html#process_process_hrtime_time) values.
`hrtime-utils` is a tiny module that exports a few useful functions that you can use to convert the value returned from `process.hrtime()` to a time unit.
- [Installation](#installation)
- [Usage](#usage)
- [API](#api)
* [hrtime2ns(time)](#hrtime2nstime)
* [hrtime2us(time)](#hrtime2ustime)
* [hrtime2ms(time)](#hrtime2mstime)
* [hrtime2s(time)](#hrtime2stime)
## Installation
```bash
$ npm i @dnlup/hrtime-utils
````
## Usage
```js
const {
hrtime2ns,
hrtime2us,
hrtime2ms,
hrtime2
} = require('@dnlup/hrtime-utils')
const time = process.hrtime()
hrtime2ns(time) // time in nanoseconds
hrtime2us(time) // time in microseconds
hrtime2ms(time) // time in milliseconds
hrtime2s(time) // time in seconds
const delta = process.hrtime(time)
hrtime2ns(delta) // delta in nanoseconds
hrtime2us(delta) // delta in microseconds
hrtime2ms(delta) // delta in milliseconds
hrtime2s(delta) // delta in seconds
```
## API
### hrtime2ns(time)
* `time` ` The return value of a [`process.hrtime()`](https://nodejs.org/docs/latest-v12.x/api/process.html#process_process_hrtime_time) call
* Returns ``
This function converts `time` to nanoseconds.
### hrtime2us(time)
* `time` ` The return value of a [`process.hrtime()`](https://nodejs.org/docs/latest-v12.x/api/process.html#process_process_hrtime_time) call
* Returns ``
This function converts `time` to microseconds.
### hrtime2ms(time)
* `time` ` The return value of a [`process.hrtime()`](https://nodejs.org/docs/latest-v12.x/api/process.html#process_process_hrtime_time) call
* Returns ``
This function converts `time` to milliseconds.
### hrtime2s(time)
* `time` ` The return value of a [`process.hrtime()`](https://nodejs.org/docs/latest-v12.x/api/process.html#process_process_hrtime_time) call
* Returns ``
This function converts `time` to seconds.