0.0.5 • Published 4 years ago

function-benchmark-util v0.0.5

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

JavaScript Function Benchmark Utility

GitHub npm type definitions

A library to benchmark JavaScript functions with microsecond precision.

Docs | Github | NPM

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.

Propertytype & Description
functionNamestring Name of the executed function
runCountnumber Execution count passed to benchmarkTimes and benchmarkTimesWithThis functions.
minnumber Minimum duration scored in microseconds
maxnumber Maximum duration scored in microseconds
averagenumber The average duration of all executions in microseconds
fnReturnsany 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

David David npm bundle size

TODO: improve docs and examples.