UNPKG

benchmark-meter

Version:

benchmark-meter is a straightforward benchmarking tool designed for measuring the performance of algorithms

49 lines (48 loc) 1.61 kB
import { DataResult } from './DataResult'; import { IBenchmarkOptions } from './types'; /** * Represents a benchmarking utility for measuring the performance of algorithms. * @since 1.0.0 */ export declare class Benchmark { private algorithms; private results; private options; /** * Creates an instance of Benchmark. * * @param {IOptions} options - The options for configuring the benchmark. */ constructor(options?: IBenchmarkOptions); /** * Adds a algorithm to the Benchmark. * * @param {string} name - The name of the algorithm. * @param {IFunction} fn - The callback function with the algorithm to be benchmarked. * @param {number | undefined} repeat - The number of times to repeat the algorithm (optional). * @throws Will throw an error if the algorithm name is already used or if the repeat count is not greater than 0. * @since 1.0.0 */ add(name: string, fn: () => unknown, repeat?: number | undefined): void; /** * Runs all added algorithms and returns the results as a DataResult instance. * * @returns {Promise<DataResult>} A promise that resolves to a DataResult instance. * @throws Will throw an error if no algorithms have been added. * @since 1.0.0 */ run(): Promise<DataResult>; /** * Clears the results array. * @since 1.0.0 */ clearResults(): void; /** * Clears the algorithm array. * @since 1.0.0 */ clearAlgorithms(): void; private executeNTimes; private calculateResults; private isNameAlreadyUsed; }