JavaScript Function Benchmark Utility
A library to benchmark JavaScript functions with microsecond precision.
Install
npm i function-benchmark-util -D
Usage
import { benchmark, benchmarkTimes } from 'function-benchmark-util';
function someFunction(param1, param2) {
// Does something
};
const result1 = benchmark(someFunction, ['param1', 'param2']);
// Running multiple iterations
const result2 = benchmarkTimes(someFunction, 10, ['param1', 'param2']);
// See the results
console.table([result1, result2]);
BenchmarkResult
object
All benchmark functions, including benchmark
, benchmarkTimes
, benchmarkWithThis
,benchmarkTimesWithThis
return a BenchmarkResult
object.
Property |
type & Description |
---|---|
functionName |
string Name of the executed function |
runCount |
number Execution count passed to benchmarkTimes and benchmarkTimesWithThis functions. |
min |
number Minimum duration scored in microseconds |
max |
number Maximum duration scored in microseconds |
average |
number The average duration of all executions in microseconds |
fnReturns |
any Latest returned function result during execution(s) |
this
context
Intentionally benchmark
and benchmarkTimes
functions set this
context of the executed function to null
to avoid ambiguity.
If you need to set this
, use benchmarkWithThis
and for multiple executions, use benchmarkTimesWithThis
.
For more, see the documentation and examples.
License
MIT © Cengiz Can
TODO: improve docs and examples.