node.js utility to measure execution time in code
npm install execution-time --save
const perf = require('execution-time')();
// At beginning of your code
perf.start();
// At end of your code
const results = perf.stop();
console.log(results.time); // in milliseconds
const perf = require('execution-time')();
// At beginning of your code, pass any name
perf.start('apiCall');
// At end of your code, pass the same name (anywhere in your flow)
const results = perf.stop('apiCall');
console.log(results.time); // in milliseconds
console.log(results.preciseWords); // in words
Sample usage with debug
const debug = require('debug')('your-module');
const perf = require('execution-time')(debug);
// At beginning of your code
perf.start();
// At end of your code
perf.stop();
also works with console.log/info/warn
const perf = require('execution-time')(console.log);
// At beginning of your code
perf.start();
// At end of your code
perf.stop();