Performance for Node.js
A superset of the User Timing API (window.performance
) for Node.js
Uses process.hrtime
to capture marks + measures to gain deeper visibility into the timings that you define in your application.
0 Dependencies!
Requirements
- Node >=
4.3.2
- NPM >=
2.14.12
Install
With yarn (recommended) in project directory:
yarn add performance-node
With npm in project directory:
npm install performance-node
Then, run your application:
const Perf = ; const timeline = ; timeline;// delay(10)timeline;timeline; const myMeasure = timeline0;// {name: 'foo-measure', startTime: 1.2, duration: 10.5, entryType: 'measure'}
Methods
const Perf = ; const timeline = ; // set markstimeline;timeline; // create a measurementtimeline; // get all timeline entries (marks + measures)timeline; // get all entries with the same nametimeline; // get all entries with the same typetimeline; // clear markstimeline; // clear measurestimeline; // clear all entriestimelineclear; // get a point in time in millisecondstimeline;
Config
offset
(number: optional)
By default, the startTime
of each mark is calculated by subracting the construction time from process.hrtime
. If you would rather the startTime map as closely as possible to process.hrtime
values, set offset: 0
. You can also supply any number as a custom offset.
const Perf = ; const timeline = offset: 0 ; timeline;// delay(10)timeline;timeline; const myMeasure = timeline0;// {name: 'foo-measure', startTime: 227851.91, duration: 10.5, entryType: 'measure'}
timestamp
(bool: optional = false)
Add a timestamp
(unix epoch) value for each mark based on Date.now()
.
const Perf = ; const timeline = timestamp: true ; timeline; const myMeasure = timeline0;// {name: 'foo-start', startTime: 1.2, duration: 0, entryType: 'mark', timestamp: 1501189303951}
Contributing
- This project uses Prettier. Please execute
npm run eslint -- --fix
to auto-format the code before submitting pull requests.