# microtime

> Get the current time in microseconds

Latest version **3.1.1** (published 2022-08-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install microtime
pnpm add microtime
yarn add microtime
bun add microtime
```

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.1.1 |
| Published | 2022-08-12 |
| First published | 2011-02-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/microtime) |
| Module format | CommonJS |
| Node | >= 14.13.0 |
| Dependencies | 2 |
| Unpacked size | 2.6 MB |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| GitHub stars | 605 |
| Author | Wade Simmons |
| Maintainers | wadey |
| Keywords | microtime, microseconds, gettimeofday |

## Links

- npm: https://www.npmjs.com/package/microtime
- Repository: https://github.com/wadey/node-microtime
- Issues: https://github.com/wadey/node-microtime/issues
- npm.io page: https://npm.io/package/microtime

## Dependencies (2)

- [node-addon-api](https://npm.io/package/node-addon-api.md) ^5.0.0
- [node-gyp-build](https://npm.io/package/node-gyp-build.md) ^4.4.0

## Recent versions

- 3.1.1 (latest) — 2022-08-12
- 3.0.0-1 (n-api) — 2019-01-31
- 3.1.0 — 2022-06-09
- 3.0.0 — 2019-02-04
- 3.0.0-0 — 2019-01-28
- 2.1.9 — 2019-01-26
- 2.1.8 — 2018-05-16
- 2.1.7 — 2018-01-03
- 2.1.6 — 2017-07-05
- 2.1.5 — 2017-06-02
- 2.1.4 — 2017-06-01
- 2.1.3 — 2017-04-11
- 2.1.2 — 2016-11-18
- 2.1.1 — 2016-04-27
- 2.1.0 — 2016-04-27
- … 25 more at https://npm.io/package/microtime/versions

## README

# node-microtime

[![npm](https://img.shields.io/npm/dm/microtime.svg)](https://www.npmjs.com/package/microtime)
[![npm](https://img.shields.io/npm/v/microtime.svg)](https://www.npmjs.com/package/microtime)

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](https://nodejs.org/api/n-api.html) 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](https://nodejs.org/api/n-api.html#n_api_n_api_version_matrix)), 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

---
_Source: https://npm.io/package/microtime · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
