Benchmark class for measuring and comparing function performance.
constructor
type new (config?: BenchmarkConfig): Benchmark
config
{}add
Add a benchmark task.
type (name: string, fn: () => unknown): this
name
task name or full task object
stringfn
Function to benchmark (if name is string). Return values are ignored.
() => unknownthisthis Benchmark instance for chaining
add
type (name: string, fn: () => unknown): this
name
stringfn
() => unknownthisadd
type (name: string, fn: () => unknown): this
name
stringfn
() => unknownthisremove
Remove a benchmark task by name.
type (name: string): this
name
name of the task to remove
stringthisthis Benchmark instance for chaining
Error- if task with given name doesn't exist
skip
Mark a task to be skipped during benchmark runs.
type (name: string): this
name
name of the task to skip
stringthisthis Benchmark instance for chaining
Error- if task with given name doesn't exist
only
Mark a task to run exclusively (along with other only tasks).
type (name: string): this
name
name of the task to run exclusively
stringthisthis Benchmark instance for chaining
Error- if task with given name doesn't exist
run
Run all benchmark tasks.
type (): Promise<BenchmarkResult[]>
Promise<BenchmarkResult[]>array of benchmark results
table
Format results as an ASCII table with percentiles, min/max, and relative performance.
type (options?: BenchmarkFormatTableOptions | undefined): string
options?
formatting options
BenchmarkFormatTableOptions | undefinedstringformatted table string
markdown
Format results as a Markdown table.
type (options?: BenchmarkFormatTableOptions | undefined): string
options?
formatting options (groups for organized output with optional baselines)
BenchmarkFormatTableOptions | undefinedstringformatted markdown string
json
Format results as JSON.
type (options?: BenchmarkFormatJsonOptions | undefined): string
options?
formatting options (pretty, include_timings)
BenchmarkFormatJsonOptions | undefinedstringJSON string
results
Get the benchmark results. Returns a shallow copy to prevent external mutation.
type (): BenchmarkResult[]
BenchmarkResult[]array of benchmark results
results_by_name
Get results as a map for convenient lookup by task name. Returns a new Map each call to prevent external mutation.
type (): Map<string, BenchmarkResult>
Map<string, BenchmarkResult>map of task name to benchmark result
reset
Reset the benchmark results. Keeps tasks intact so benchmarks can be rerun.
type (): this
thisthis Benchmark instance for chaining
clear
Clear everything (results and tasks). Use this to start fresh with a new set of benchmarks.
type (): this
thisthis Benchmark instance for chaining
summary
Get a quick text summary of the fastest task.
type (): string
stringhuman-readable summary string