hirestime

2018-09-23 admin

hirestime是什么

什么是hirestime,thin wrapper around process.hrtime

hirestime使用教程帮助文档

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)

本站文章除注明转载外,均为本站原创或编译。欢迎任何形式的转载,但请务必注明出处。

转载请注明:文章转载自 JavaScript中文网 [https://www.javascriptcn.com]

本文地址:https://www.javascriptcn.com/read-41021.html

文章标题:hirestime

回到顶部