@pjchender/function-benchmarker
v1.0.5
Published
A simple benchmark for testing function performance
Downloads
1
Maintainers
Readme
Function Benchmarker
A simple benchmark for testing function performance. Through the package, you can compare the cost time of different functions.
Guide
Import '@pjchender/function-benchmarker` and make the function you want to test as a parameter. Function-benchmarker will return the cost time executing the function in milliseconds.
const benchmarker = require('@pjchender/function-benchmarker');
function jsonStringify() {
JSON.stringify({
foo: 'bar',
});
}
const costTime = benchmarker(jsonStringify);
console.log('costTime', costTime);
API
By default, function-benchmarker will run the function to test for 1,000,000 times and calculate the cost time (ms). You can pass the times for executing the function as the second parameter.
const costTime = benchmarker(functionToTest, [times]);
Test
$ npm test
LICENSE
MIT