microtime
Get the current time in microseconds
Last updated 8 years ago by wadey .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install microtime 
SYNC missed versions from official npm registry.

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.

Current Tags

  • 4.0.1                                ...           latest (16 days ago)
  • 3.0.0-1                                ...           n-api (8 years ago)

41 Versions

  • 4.0.1                                ...           16 days ago
  • 3.1.1                                ...           4 years ago
  • 3.1.0                                ...           4 years ago
  • 3.0.0                                ...           8 years ago
  • 3.0.0-1                                ...           8 years ago
  • 3.0.0-0                                ...           8 years ago
  • 2.1.9                                ...           8 years ago
  • 2.1.8                                ...           9 years ago
  • 2.1.7                                ...           9 years ago
  • 2.1.6                                ...           9 years ago
  • 2.1.5                                ...           9 years ago
  • 2.1.4                                ...           9 years ago
  • 2.1.3                                ...           10 years ago
  • 2.1.2                                ...           10 years ago
  • 2.1.1                                ...           11 years ago
  • 2.1.0                                ...           11 years ago
  • 1.5.0                                ...           11 years ago
  • 2.0.0                                ...           11 years ago
  • 1.4.2                                ...           12 years ago
  • 1.4.1                                ...           12 years ago
  • 1.4.0                                ...           12 years ago
  • 1.3.0                                ...           12 years ago
  • 1.2.0                                ...           12 years ago
  • 1.1.1                                ...           12 years ago
  • 1.1.0                                ...           12 years ago
  • 1.0.1                                ...           12 years ago
  • 1.0.0                                ...           12 years ago
  • 0.6.0                                ...           13 years ago
  • 0.5.1                                ...           13 years ago
  • 0.5.0                                ...           13 years ago
  • 0.4.0                                ...           13 years ago
  • 0.3.3                                ...           14 years ago
  • 0.3.2                                ...           14 years ago
  • 0.3.1                                ...           15 years ago
  • 0.3.0                                ...           15 years ago
  • 0.2.0                                ...           15 years ago
  • 0.1.3-1                                ...           16 years ago
  • 0.1.3                                ...           16 years ago
  • 0.1.2                                ...           16 years ago
  • 0.1.1                                ...           16 years ago
  • 0.1.0                                ...           16 years ago
Maintainers (1)
Downloads
Total 142
Today 6
This Week 35
This Month 100
Last Day 5
Last Week 10
Last Month 23
Dependencies (2)
Dev Dependencies (6)

© 2010 - cnpmjs.org x YWFE | Home | YWFE