• Stars
    star
    598
  • Rank 74,853 (Top 2 %)
  • Language
    C++
  • License
    MIT License
  • Created almost 14 years ago
  • Updated 11 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Get the current time in microseconds

node-microtime

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.''

N-API Support

As of version 3.0.0, this library is built using the N-API library. This should allow you to upgrade to newer versions of Node.js without having to reinstall / rebuild this library.

Version 3.0.0 and later also bundle prebuilt binaries for common systems in the npm package itself. These will be used if the version of Node you are using supports N-API (>= v6.14.2), otherwise the binary will be recompiled on install.

Installation

npm install microtime

Usage

microtime.now()

Get the current time in microseconds as an integer.

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

More Repositories

1

gocovmerge

Merge coverprofile results from multiple go cover runs
Go
209
star
2

node-thrift

ARCHIVED: Please look upstream at http://thrift.apache.org/ or https://github.com/apache/thrift
JavaScript
165
star
3

python-fitbit

A simple Fitbit API client
Python
70
star
4

python-ostrich

A stats collector & reporter: port of the Scala Ostrich library
Python
39
star
5

dotfiles

My dotfiles (.zshrc, .vimrc, .gitconfig, etc)
Shell
34
star
6

decimaljson

JavaScript JSON encoder/decoder that preserves precision.
JavaScript
27
star
7

go-zipkin

Golang Zipkin Tracing Client
Go
18
star
8

go-rounding

Rounding and truncation methods for big.Rat
Go
15
star
9

ko

Knockout Competition Stats Collector
JavaScript
13
star
10

statsny

Ephemeral API stats
HTML
12
star
11

node-syncrepl

Call asynchronous methods with ease
JavaScript
9
star
12

node-geoip

JavaScript
7
star
13

cryptorand

Package cryptorand provides a math/rand.Source64 implementation of crypto/rand
Go
7
star
14

fpys2

Fork of the fpys Python Flexible Payments Service library, converted to API version 2008-09-17
Python
6
star
15

zshscripts

ZSH Scripts
5
star
16

go-diff-mod

Pretty diff for resolved Go dependencies, for commits and pull requests
Go
5
star
17

node-unicorn

Unicorn-like server for node using web workers
JavaScript
4
star
18

taplist

WORK IN PROGRESS. Detect when new beers are on tap in SF.
Python
4
star
19

rabbithole

AMQP / RabbitMQ REST interface.
JavaScript
3
star
20

json

Fork of json.org Java library that will play nice with the Java Collections Framework
Java
3
star
21

nebula-tools

Personal tools for Nebula
Shell
2
star
22

geebus

Campfire bot
JavaScript
2
star
23

gnip-java

OUTDATED Java 1.5 port of the Gnip Java library. See README
Java
2
star
24

twitter-stream

Simple Twitter Streaming API client
Java
2
star
25

mailplaner

Create a copy of Mailplane.app
Shell
1
star
26

whereinthe

run with: twistd -ny whereinthe.py
JavaScript
1
star
27

gomake

Generic Go Makefile with helpful targets
Makefile
1
star
28

go-get-ssh-cert

Grab the SSH certificate from a remote server
Go
1
star
29

testing-repo

Nothing to see here, move along
1
star
30

node-ostrich

A stats collector & reporter: port of the Scala Ostrich library
JavaScript
1
star