benchmark_format.ts

Declarations
#

7 declarations

view source

benchmark_format_json
#

benchmark_format.ts view source

(results: BenchmarkResult[], options?: BenchmarkFormatJsonOptions | undefined): string

Format results as JSON.

results

array of benchmark results

type BenchmarkResult[]

options?

formatting options

type BenchmarkFormatJsonOptions | undefined
optional

returns

string

JSON string

examples

console.log(format_json(results)); console.log(format_json(results, {pretty: false})); console.log(format_json(results, {include_timings: true}));

benchmark_format_markdown
#

benchmark_format.ts view source

(results: BenchmarkResult[], baseline?: string | undefined): string

Format results as a Markdown table with key metrics. All times use the same unit for easy comparison.

results

array of benchmark results

type BenchmarkResult[]

baseline?

optional task name to use as baseline for comparison (defaults to fastest)

type string | undefined
optional

returns

string

formatted markdown table string

examples

console.log(benchmark_format_markdown(results)); // | Task Name | ops/sec | p50 (Ξs) | p75 (Ξs) | p90 (Ξs) | p95 (Ξs) | p99 (Ξs) | min (Ξs) | max (Ξs) | vs Best | // |------------|------------|----------|----------|----------|----------|----------|----------|----------|----------| // | slugify v2 | 1,237,144 | 0.81 | 0.85 | 0.89 | 0.95 | 1.20 | 0.72 | 2.45 | baseline | // | slugify | 261,619 | 3.82 | 3.95 | 4.12 | 4.35 | 5.10 | 3.21 | 12.45 | 4.73x |

benchmark_format_markdown_grouped
#

benchmark_format.ts view source

(results: BenchmarkResult[], groups: BenchmarkGroup[]): string

Format results as grouped Markdown tables with headers between groups.

results

array of benchmark results

type BenchmarkResult[]

groups

array of group definitions

type BenchmarkGroup[]

returns

string

formatted markdown string with group headers and tables

examples

const groups = [ { name: 'Fast Paths', filter: (r) => r.name.includes('fast'), baseline: 'fast/reference' }, { name: 'Slow Paths', filter: (r) => r.name.includes('slow') }, ]; console.log(benchmark_format_markdown_grouped(results, groups)); // ### Fast Paths // | Task Name | ops/sec | ... | vs fast/reference | // |-----------|---------|-----|-------------------| // | ... | ... | ... | ... | // // ### Slow Paths // | Task Name | ops/sec | ... | vs Best | // |-----------|---------|-----|---------| // | ... | ... | ... | ... |

benchmark_format_number
#

benchmark_format.ts view source

(n: number, decimals?: number) => string

Format a number with fixed decimal places and thousands separators.

see also

  • ``format_number`` in maths.ts for the underlying implementation.

benchmark_format_table
#

benchmark_format.ts view source

(results: BenchmarkResult[], baseline?: string | undefined): string

Format results as an ASCII table with percentiles, min/max, and relative performance. All times use the same unit for easy comparison.

results

array of benchmark results

type BenchmarkResult[]

baseline?

optional task name to use as baseline for comparison (defaults to fastest)

type string | undefined
optional

returns

string

formatted table string with enhanced metrics

examples

console.log(benchmark_format_table(results)); // ┌─────────────┮────────────┮──────────┮──────────┮──────────┮──────────┮──────────┮──────────┮──────────┮──────────┐ // │ Task Name │ ops/sec │ p50 (Ξs) │ p75 (Ξs) │ p90 (Ξs) │ p95 (Ξs) │ p99 (Ξs) │ min (Ξs) │ max (Ξs) │ vs Best │ // ├─────────────┾────────────┾──────────┾──────────┾──────────┾──────────┾──────────┾──────────┾──────────┾──────────â”Ī // │ slugify v2 │ 1,237,144 │ 0.81 │ 0.85 │ 0.89 │ 0.95 │ 1.20 │ 0.72 │ 2.45 │ baseline │ // │ slugify │ 261,619 │ 3.82 │ 3.95 │ 4.12 │ 4.35 │ 5.10 │ 3.21 │ 12.45 │ 4.73x │ // └─────────────â”ī────────────â”ī──────────â”ī──────────â”ī──────────â”ī──────────â”ī──────────â”ī──────────â”ī──────────â”ī──────────┘

benchmark_format_table_grouped
#

benchmark_format.ts view source

(results: BenchmarkResult[], groups: BenchmarkGroup[]): string

Format results as a grouped table with visual separators between groups.

results

array of benchmark results

type BenchmarkResult[]

groups

array of group definitions

type BenchmarkGroup[]

returns

string

formatted table string with group separators

examples

const groups = [ { name: 'FAST PATHS', filter: (r) => r.name.includes('fast') }, { name: 'SLOW PATHS', filter: (r) => r.name.includes('slow') }, ]; console.log(benchmark_format_table_grouped(results, groups)); // ðŸ“Ķ FAST PATHS // ┌────┮─────────────┮────────────┮...┐ // │ 🐆 │ fast test 1 │ 1,237,144 │...│ // │ 🐇 │ fast test 2 │ 261,619 │...│ // └────â”ī─────────────â”ī────────────â”ī...┘ // // ðŸ“Ķ SLOW PATHS // ┌────┮─────────────┮────────────┮...┐ // │ ðŸĒ │ slow test 1 │ 10,123 │...│ // └────â”ī─────────────â”ī────────────â”ī...┘

BenchmarkFormatJsonOptions
#

benchmark_format.ts view source

BenchmarkFormatJsonOptions

pretty

Whether to pretty-print (default: true)

type boolean

include_timings

Whether to include raw timings array (default: false, can be large)

type boolean

Depends on
#

Imported by
#