Simple Performance Measurement for Node.js
npm install timeit-jsMeasure the average execution time of a function. If you find any bugs or have suggestions feel free to help and fork the package.
``sh`
npm i timeit-js
`js`
const timeit = require('timeit-js')
`js`
/**
* Measure the average execution time of a function
* @param {Function} fn A function for performance measurement
* @param {Array} args Function arguments
* @param {Object} options
* @returns {Number} Result in milliseconds
*/
timeit(fn, args=[], options={})
| Parameter | Option | Default
|-----------|---------|--------:
e | Number of function executions | 1000r | Number of test repetitions | 1l | Show timeit-result in logs | trued | Number of decimals in Logging text | 6
`js
const timeit = require('timeit-js')
function sum () {
return [...arguments].reduce((p, c) => p+c, 0)
}
timeit(sum, args=[1, 2, 3, 4], options={e: 100000, r: 100, d: 6})
``