Skip to content

A small collection of useful functions to work with Node.js `process.hrtime` values

License

Notifications You must be signed in to change notification settings

dnlup/hrtime-utils

This branch is 1 commit ahead of next.

Folders and files

NameName
Last commit message
Last commit date
Jul 14, 2021
Mar 17, 2021
Oct 13, 2020
Nov 9, 2020
Oct 13, 2020
Nov 22, 2020
Nov 7, 2020
Dec 23, 2020
Dec 5, 2022
Dec 5, 2022
Nov 9, 2020

Repository files navigation

hrtime-utils

npm version Tests codecov Known Vulnerabilities

A small collection of useful functions to work with Node.js process.hrtime 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

$ npm i @dnlup/hrtime-utils

Usage

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)

This function converts time to nanoseconds.

hrtime2us(time)

This function converts time to microseconds.

hrtime2ms(time)

This function converts time to milliseconds.

hrtime2s(time)

This function converts time to seconds.