eslint-rule-benchmark
Version:
Benchmark ESLint rules with detailed performance metrics for CI and plugin development
56 lines (55 loc) • 2.21 kB
TypeScript
import { BenchmarkMetrics } from '../../types/benchmark-metrics'
import { BenchmarkConfig } from '../../types/benchmark-config'
import { TestCase } from '../../types/test-case'
/** Processed benchmark result for a single task. */
export interface ProcessedBenchmarkTask {
/** Metrics calculated from the benchmark samples. */
metrics: BenchmarkMetrics
/** Name of the benchmark task. */
name: string
}
/** Parameters for running a benchmark. */
interface RunBenchmarkParameters {
/** Optional path to custom ESLint config file. */
eslintConfigFile?: string
/** Configuration for the benchmark. */
config: BenchmarkConfig
/** Path to the configuration directory. */
configDirectory: string
/** Test cases to benchmark. */
testCases: TestCase[]
}
/**
* Runs benchmarks based on the provided test cases and configuration.
*
* This function orchestrates the benchmarking process using tinybench. It
* creates a new ESLint instance for each unique TestCase (based on its rule
* configuration) to ensure isolation. Each code sample within a TestCase is
* then added as an individual task to a tinybench Bench instance. Finally, it
* runs all collected tasks and returns their results.
*
* If no test cases are provided, or if no valid benchmark tasks can be
* generated (e.g., due to errors in ESLint instance creation or lack of
* runnable samples), it will return null.
*
* @example
* // Assuming testCases and config are defined:
* const results = await runBenchmark({ testCases, config })
* if (results) {
* results.forEach(processedTask => {
* console.log(
* `Task: ${processedTask.name}, Ops/sec: ${processedTask.metrics.hz}`,
* )
* })
* }
*
* @param parameters - The parameters for running the benchmark, including the
* overall benchmark configuration and an array of test cases.
* @returns A promise that resolves to an array of ProcessedBenchmarkTask
* objects, each containing the name and calculated metrics for a benchmarked
* code sample. Returns null if no tasks were run.
*/
export declare function runBenchmark(
parameters: RunBenchmarkParameters,
): Promise<ProcessedBenchmarkTask[] | null>
export {}