@node-cli/perf
TypeScript icon, indicating that this package has built-in type declarations

1.0.6 • Public • Published

Node CLI perf package

npm

Performance tools for nodejs command-line applications.

Performance

The class Performance is a wrapper around nodejs Performance measurement APIs.

It is intended for an extremely simple case:

  • start performance monitoring
  • do something that takes a while
  • stop performance monitoring
  • read how much time passed between start and stop (in milliseconds)
  • rinse and repeat

Methods

Method Description
start Starts measuring performance
stop Stops measuring performance and store the result
Getter Type Description
results Object
results.duration Number Time in milliseconds

Examples

Basic performance gathering

import { Performance } from "@node-cli/perf;
const perf = new Performance();

// Somewhere in your code, you want to start measuring performance:
perf.start();
// Do long lasting actions
(...)
// When done, tell performance to stop:
perf.stop();
// The duration can now be found in the Performance class getter `results`:
console.log(`It took ${perf.results.duration} milliseconds to run...`);

Multiple performance gatherings

import { Performance } from "@node-cli/perf;
const perf = new Performance();

// Somewhere in your code, you want to start measuring performance:
perf.start();
// Do long lasting actions
(...)
// When done, tell performance to stop:
perf.stop();
// Save the results
const res1 = perf.results.duration;

// Further down in your code, start measuring another performance:
perf.start();
// Do other long lasting actions
(...)
// When done, tell performance to stop:
perf.stop();
// Save the results
const res2 = perf.results.duration;

// -> res1 and res2 will have 2 different duration results.

License

MIT © Arno Versini

Readme

Keywords

none

Package Sidebar

Install

npm i @node-cli/perf

Weekly Downloads

2

Version

1.0.6

License

MIT

Unpacked Size

9.48 kB

Total Files

7

Last publish

Collaborators

  • aversini