# browser-hrtime

> use process.hrtime() in the browser

Latest version **1.1.8** (published 2020-10-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install browser-hrtime
pnpm add browser-hrtime
yarn add browser-hrtime
bun add browser-hrtime
```

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.8 |
| Published | 2020-10-19 |
| First published | 2020-04-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 9.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Vlad Tansky |
| Maintainers | niftylettuce, vl.tansky |
| Keywords | hrtime, process, perfomance, angular, node |

## Links

- npm: https://www.npmjs.com/package/browser-hrtime
- Repository: https://github.com/cabinjs/browser-hrtime
- Homepage: https://github.com/cabinjs/browser-hrtime#readme
- Issues: https://github.com/cabinjs/browser-hrtime/issues
- npm.io page: https://npm.io/package/browser-hrtime

## Alternatives

- [@expo/fingerprint](https://npm.io/package/@expo/fingerprint.md) — 6.2M weekly downloads
- [@azure/monitor-opentelemetry-exporter](https://npm.io/package/@azure/monitor-opentelemetry-exporter.md) — 850.0K weekly downloads
- [@azure/monitor-opentelemetry](https://npm.io/package/@azure/monitor-opentelemetry.md) — 624.0K weekly downloads
- [@posthog/ai](https://npm.io/package/@posthog/ai.md) — 423.3K weekly downloads
- [fakefilter](https://npm.io/package/fakefilter.md) — 63.9K weekly downloads

## Recent versions

- 1.1.8 (latest) — 2020-10-19
- 1.1.7 — 2020-08-11
- 1.1.6 — 2020-06-11
- 1.1.5 — 2020-04-30
- 1.1.4 — 2020-04-30
- 1.1.3 — 2020-04-30
- 1.1.2 — 2020-04-29
- 1.1.1 — 2020-04-29
- 1.1.0 — 2020-04-29
- 1.0.4 — 2020-04-27
- 1.0.3 — 2020-04-27
- 1.0.2 — 2020-04-27
- 1.0.1 — 2020-04-27
- 1.0.0 — 2020-04-27

## README

# browser-hrtime
browser support for `process.hrtime()`.

![Node.js CI](https://github.com/cabinjs/browser-hrtime/workflows/Node.js%20CI/badge.svg)
[![Coverage Status](https://coveralls.io/repos/github/cabinjs/browser-hrtime/badge.svg?branch=master)](https://coveralls.io/github/cabinjs/browser-hrtime?branch=master)
[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
[![license](https://img.shields.io/github/license/cabinjs/parse-request.svg)](LICENSE)

## :package: Installation

#### npm

```bash
npm install browser-hrtime
```

#### yarn

```bash
yarn add browser-hrtime
```

## :page_with_curl: Examples
### NodeJS
#### As a polyfill
```js
require('browser-hrtime');

const time = process.hrtime();// [ 1800216, 25 ]
setTimeout(() => {
  const diff = process.hrtime(time);// [ 1, 552 ]
  console.log(`Benchmark took ${diff[0] * 1e9 + diff[1]} nanoseconds`);// Benchmark took 1000000552 nanoseconds
}, 1000);
```
### As a function
```js
const hrtime = require('browser-hrtime');

const time = hrtime();// [ 1800216, 25 ]
setTimeout(() => {
  const diff = hrtime(time);// [ 1, 552 ]
  console.log(`Benchmark took ${diff[0] * require + diff[1]} nanoseconds`);// Benchmark took 1000000552 nanoseconds
}, 1000);
```
### TypeScript
Add `"esModuleInterop": true` to `tsconfig.json` or use: 
```js
import hrtime = require('browser-hrtime');
```

## Web with module

```js
import * as hrtime from 'browser-hrtime';

const time = hrtime();// [ 1800216, 25 ]
setTimeout(() => {
  const diff = hrtime(time);// [ 1, 552 ]
  console.log(`Benchmark took ${diff[0] * 1e9 + diff[1]} nanoseconds`);// Benchmark took 1000000552 nanoseconds
}, 1000);
```

or as polyfill:
```js
import 'browser-hrtime';
const time = process.hrtime();// [ 1800216, 25 ]

setTimeout(() => {
  const diff = process.hrtime(time);// [ 1, 552 ]
  console.log(`Benchmark took ${diff[0] * 1e9 + diff[1]} nanoseconds`);// Benchmark took 1000000552 nanoseconds
}, 1000);
```
### Usage as an Angular polyfill:
add to `src/polyfills.ts`:
`import 'browser-hrtime';`
Add @types/node to your Angular app

```bash
npm i -S @types/node
```

Then in `tsconfig.json`
```json
"angularCompilerOptions": {
    "types" : ["node"]
    ....
}
```

## Web

```html
<script src="node_modules/browser-hrtime/lib/hrtime.js"></script>
<!-- Or from CDN: -->
<!-- <script crossorigin src="https://unpkg.com/browser-hrtime/lib/hrtime.js"></script> -->
```
```javascript
    console.log(hrtime());
    const first = process.hrtime();
    console.log(first);
    console.log(process.hrtime(first));
```

see [NodeJS documenation](https://nodejs.org/api/process.html#process_process_hrtime_time) for detailed process.hrtime API


## Contribution
Clone project from Github

```bash
git clone git@github.com:cabinjs/browser-hrtime.git
```

Install npm packages

```bash
cd browser-hrtime
npm install
```

Build sources:

```bash
npm run build
```
Run tests:

```
npm run test
```

### License

[MIT](LICENSE)

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