import { IReporter } from './reporters'; import { RunFunction, IBenchmarkCase } from './suite'; import { MaybeAsync } from './async'; import { IOptions } from './options'; /** * A middleware function for the benchmark. Invoked directly before the * benchmark starts running. */ export declare type Middleware = (benchmark: Readonly, next: (options: Readonly) => Promise) => Promise; /** * Options passed to the `benchmark` function. */ export interface IBenchmarkOptions { /** * Optional funciton to override how benchmarks are run. Useful mostly * for testing purposes. */ runFunction?: RunFunction; /** * Optional profiler instance that can be used to run CPU profiles * on benchmarks. */ middleware?: Middleware[]; /** * Takes the benchmark API, and should register all benchmarks using * the `api.bench()` method before turning. */ prepare: (setupFn: IBenchmarkApi) => Promise | void; /** * Reporter to use for returning results. */ reporter: IReporter; } /** * API passed to the prepare step of the benchmarking. */ export interface IBenchmarkApi { /** * Adds the given function to the benchmark. * @param name Benchmark name * @param fn Function to run, can return a promise or call a callback * @param options Benchmark options for benchmark.js. Note that setup and * teardown are allowed to be async, however! */ bench(name: string, fn: MaybeAsync, options?: IOptions): void; /** * Creates a nested 'scope' of benchmarks. Options are inherited and * names are prefixed with the suite name. */ suite(name: string, fn: () => void, options?: IOptions): void; /** * Sets an option for all benchmarks in the current suite and nested suites. */ set(key: K, value: IOptions[K]): void; /** * A stub function that 'uses' the value, preventing it from being optimized * away. */ retain(value: unknown): void; } export declare function benchmark({ runFunction, prepare, reporter, middleware, }: IBenchmarkOptions): Promise;