chronolite 🕰️
chronolite is a microlibrary for timing, comparing and benchmarking JavaScript functions. It supports both synchronous and asynchronous functions. Common use cases include performance benchmarking for a function, and benchmarking multiple functions against each other.
Install
For npm:
npm install chronolite
For yarn:
yarn add chronolite
Usage
chronolite has 4 core methods:
- time - Return the running time of a synchronous function
- timeAsync - Return the running time of a async function (function must return a promise)
- compare - Find the fastest function out of an array of functions
- compareAsync - Find the fastest function out of an array of async functions
Methods take objects or arrays of objects of the following schema:
id: "someFunction" // - string (optional) binding: null // object (optional) - The object to bind the function to (defaults to null) fn: someFunc // function fnArgs: 1 2 3 // array - The array of arguments
Here is an example of using the time method:
const timer = ; const fn = { // Synthetic wait const ms = input * Math * 1; const start = Date; let now = start; while now - start < ms now = Date; return "finished"; }; const arg = 10; const iterations = 15; const time = timer; console;
License
MIT