benchly
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

benchly · license

A lightweight benchmarking library for measuring the performance of synchronous and asynchronous functions in JavaScript and TypeScript.

Installation

npm install benchly --save-dev
// or
yarn add benchly --dev

Usage

Synchronous Functions

import benchmark from 'benchly';

const syncFunction = () => {
  for (let i = 0; i < 1000; i++) {}
};

const result = benchmark(syncFunction, { iterations: 1000 });
console.log(`Time taken: ${result} ms`);

Asynchronous Functions

import benchmark from 'benchly';

const asyncFunction = async () => {
  await new Promise((resolve) => setTimeout(resolve, 10));
};

(async () => {
  const result = await benchmark(asyncFunction, { iterations: 100 });
  console.log(`Time taken: ${result} ms`);
})();

API

Parameters

  • fn: The function to benchmark.
  • options.iterations (optional): The number of iterations to run the benchmark. Default: 100.

Returns

  • The average time taken (in milliseconds) for the function to execute over the specified number of iterations.

License

MIT

Package Sidebar

Install

npm i benchly

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

154 kB

Total Files

62

Last publish

Collaborators

  • evandrolg