Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including hirestime with all npm packages installed. Try it out:

var hirestime = require("hirestime")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

hirestime v3.2.1

thin wrapper around process.hrtime

hirestime Build Status

NPM

NPM

hirestime is a thin wrapper around the common time measuring APIs (node and the browser). Uses process.hrtime() on node, the performance API in the browser and falls back to Date if neither is available.

Installation

npm install hirestime

hirestime()

returns a function:

returnedFunction([unit])

Returns the elapsed time since the call of hirestime in milliseconds.
An optional unit parameter can be specified that will modify the unit in which the elapsed time will be calculated.

Possible Parameters

  • hirestime.S elapsed time in seconds
  • hirestime.MS elapsed time in milliseconds
  • hirestime.NS elapsed time in nanoseconds

Examples

By default the time is measured in milliseconds:

const hirestime = require('hirestime')

//startpoint of the time measurement
const getElapsed = hirestime()

setTimeout(_ => {
    //returns the elapsed milliseconds
    console.log(getElapsed())
}, 1000)

Optionally the unit can be set to be seconds or nanoseconds:

const hirestime = require('hirestime')

//startpoint of the time measurement
const getElapsed = hirestime()

setTimeout(_ => {
   //returns the elapsed seconds
   console.log(getElapsed(hirestime.S))
}, 1000)

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free