Socket
Socket
Sign inDemoInstall

microtime

Package Overview
Dependencies
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

microtime

Get the current time in microseconds


Version published
Weekly downloads
87K
decreased by-0.83%
Maintainers
1
Weekly downloads
 
Created
Source

node-microtime

Travis Build AppVeyor Build npm npm

Date.now() will only give you accuracy in milliseconds. This module calls gettimeofday(2) to get the time in microseconds and provides it in a few different formats. The same warning from that function applies: The resolution of the system clock is hardware dependent, and the time may be updated continuously or in ``ticks.''

Installation

npm install microtime

Usage

microtime.now()

Get the current time in microseconds as an integer. Since JavaScript can only represent integer values accurately up to Math.pow(2, 53), this value will be accurate up to Tue, 05 Jun 2255 23:47:34 GMT.

microtime.nowDouble()

Get the current time in seconds as a floating point number with microsecond accuracy (similar to time.time() in Python and Time.now.to_f in Ruby).

microtime.nowStruct()

Get the current time and return as a list with seconds and microseconds (matching the return value of gettimeofday(2)).

Example

> var microtime = require('microtime')
> microtime.now()
1297448895297028
> microtime.nowDouble()
1297448897.600976
> microtime.nowStruct()
[ 1297448902, 753875 ]

Estimating clock resolution

Starting with version 0.1.3, there is a test script that tries to guess the clock resolution. You can run it with npm test microtime. Example output:

microtime.now() = 1298960083489806
microtime.nowDouble() = 1298960083.511521
microtime.nowStruct() = [ 1298960083, 511587 ]

Guessing clock resolution...
Clock resolution observed: 1us

Warning for Cygwin users

It appears that Cygwin only implements gettimeofday(2) with millisecond accuracy.

Keywords

FAQs

Package last updated on 16 May 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc