Performance tools for nodejs command-line applications.
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
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 |
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...`);
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.
MIT © Arno Versini