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