Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
vltansky authored Apr 29, 2020
1 parent d568ab9 commit 212deae
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,6 @@ browser support for `process.hrtime()`.
# Install
`npm i browser-hrtime`
# Usage
## NodeJS
```
const hrtime = require('browser-hrtime');
const NS_PER_SEC = 1e9;
const time = hrtime();
// [ 1800216, 25 ]
setTimeout(() => {
const diff = hrtime(time);
// [ 1, 552 ]
console.log(`Benchmark took ${diff[0] * NS_PER_SEC + diff[1]} nanoseconds`);
// Benchmark took 1000000552 nanoseconds
}, 1000);
```

## Typescript & ECMAScript
```
import * as hrtime from 'browser-hrtime';
Expand Down Expand Up @@ -59,7 +41,7 @@ setTimeout(() => {
### usage as an Angular polyfill:
add to `src/polyfills.ts`:
`import 'browser-hrtime';`
# Use in browser
## Use in browser
```
<!DOCTYPE html>
<html>
Expand All @@ -79,4 +61,21 @@ add to `src/polyfills.ts`:
</html>
```

## NodeJS
```
const hrtime = require('browser-hrtime');//In NodeJS will return the process.hrtime() instance
const NS_PER_SEC = 1e9;
const time = hrtime();
// [ 1800216, 25 ]
setTimeout(() => {
const diff = hrtime(time);
// [ 1, 552 ]
console.log(`Benchmark took ${diff[0] * NS_PER_SEC + diff[1]} nanoseconds`);
// Benchmark took 1000000552 nanoseconds
}, 1000);
```
see [NodeJS documenation](https://nodejs.org/api/process.html#process_process_hrtime_time) for more examples

0 comments on commit 212deae

Please sign in to comment.