UNPKG

@monstermann/tinybench-pretty-printer

Version:
152 lines (148 loc) 7.69 kB
import * as _monstermann_tables from '@monstermann/tables'; import { Style, Alignment, Borders, CreateCliTableConfig } from '@monstermann/tables'; import { Task, TaskResult, Bench } from 'tinybench'; type TaskWithResult = Task & { result: TaskResult; }; type CountMethod = 'none' | 'shortest' | 'highest' | 'lowest' | 'mean' | 'thousands' | 'millions' | 'billions'; type DurationMethod = 'shortest' | 'highest' | 'lowest' | 'mean' | 'nanoseconds' | 'microseconds' | 'milliseconds' | 'seconds'; type SummaryMethod = 'x' | '%'; type SortMethod = false | 'asc' | 'desc' | ((tasks: TaskWithResult[]) => TaskWithResult[]); type DefaultColumn = 'name' | 'summary' | 'ops' | 'time' | 'margin' | 'samples'; type ColumnContext = { task: TaskWithResult; tasks: TaskWithResult[]; fastestTask: TaskWithResult; slowestTask: TaskWithResult; locales: Intl.LocalesArgument; formatNumber: (value: number) => string; formatDuration: (method: DurationMethod, value: number, values: number[]) => string; formatCount: (method: CountMethod, value: number, values: number[]) => string; }; type ColumnOptions = { header: string; headerStyle: Style[]; headerAlignment: Alignment; rowStyle: Style[]; rowAlignment: Alignment; }; type Column = ColumnOptions & { content: (ctx: ColumnContext) => string; }; type Columns<T extends string> = Record<T, Column>; type NameOptions = Partial<ColumnOptions>; type SummaryOptions = Partial<ColumnOptions & { method: SummaryMethod; fastestTitle: string; }>; type OpsOptions = Partial<ColumnOptions & { method: CountMethod; }>; type TimeOptions = Partial<ColumnOptions & { method: DurationMethod; }>; type MarginOptions = Partial<ColumnOptions>; type SamplesOptions = Partial<ColumnOptions & { method: CountMethod; }>; interface TinybenchPrinter<T extends string> { order: (order: T[]) => TinybenchPrinter<T>; column: <U extends string>(name: U, column: Column) => TinybenchPrinter<T | U>; name: (options: NameOptions) => TinybenchPrinter<T>; summary: (options: SummaryOptions) => TinybenchPrinter<T>; ops: (options: OpsOptions) => TinybenchPrinter<T>; time: (options: TimeOptions) => TinybenchPrinter<T>; margin: (options: MarginOptions) => TinybenchPrinter<T>; samples: (options: SamplesOptions) => TinybenchPrinter<T>; locales: (locales: Intl.LocalesArgument) => TinybenchPrinter<T>; sort: (method: SortMethod) => TinybenchPrinter<T>; maxWidth: (maxWidth: number) => TinybenchPrinter<T>; stdout: (stdout: NodeJS.WriteStream) => TinybenchPrinter<T>; padding: (padding: number) => TinybenchPrinter<T>; borders: (borders: Borders) => TinybenchPrinter<T>; borderStyle: (style: Style[]) => TinybenchPrinter<T>; useHeader: (use: boolean) => TinybenchPrinter<T>; useTopBorder: (use: boolean) => TinybenchPrinter<T>; useBottomBorder: (use: boolean) => TinybenchPrinter<T>; useLeftBorder: (use: boolean) => TinybenchPrinter<T>; useRightBorder: (use: boolean) => TinybenchPrinter<T>; useDividerBorder: (use: boolean) => TinybenchPrinter<T>; useHeaderSeparator: (use: boolean) => TinybenchPrinter<T>; useRowSeparator: (use: boolean) => TinybenchPrinter<T>; toCli: (bench: Bench) => string; toMarkdown: (bench: Bench) => string; prepareTableConfig: (bench: Bench) => CreateCliTableConfig<T>; } type Config = { order: string[]; columns: Columns<string>; locales?: Intl.LocalesArgument; sort?: SortMethod; maxWidth?: number; stdout?: NodeJS.WriteStream; padding?: number; borders?: Borders; borderStyle?: Style[]; useHeader?: boolean; useTopBorder?: boolean; useBottomBorder?: boolean; useLeftBorder?: boolean; useRightBorder?: boolean; useDividerBorder?: boolean; useHeaderSeparator?: boolean; useRowSeparator?: boolean; }; declare class TinybenchPrinterImpl { config: Config; constructor(config: Config); merge(config: Partial<Config>): TinybenchPrinterImpl; order(order: string[]): TinybenchPrinterImpl; column(name: string, column: Column): TinybenchPrinterImpl; name(options: NameOptions): TinybenchPrinterImpl; summary(options: SummaryOptions): TinybenchPrinterImpl; ops(options: OpsOptions): TinybenchPrinterImpl; time(options: TimeOptions): TinybenchPrinterImpl; margin(options: MarginOptions): TinybenchPrinterImpl; samples(options: SamplesOptions): TinybenchPrinterImpl; locales(locales: Intl.LocalesArgument): TinybenchPrinterImpl; sort(sort: SortMethod): TinybenchPrinterImpl; maxWidth(maxWidth: number): TinybenchPrinterImpl; stdout(stdout: NodeJS.WriteStream): TinybenchPrinterImpl; padding(padding: number): TinybenchPrinterImpl; borders(borders: Borders): TinybenchPrinterImpl; borderStyle(borderStyle: Style[]): TinybenchPrinterImpl; useHeader(useHeader: boolean): TinybenchPrinterImpl; useTopBorder(useTopBorder: boolean): TinybenchPrinterImpl; useBottomBorder(useBottomBorder: boolean): TinybenchPrinterImpl; useLeftBorder(useLeftBorder: boolean): TinybenchPrinterImpl; useRightBorder(useRightBorder: boolean): TinybenchPrinterImpl; useDividerBorder(useDividerBorder: boolean): TinybenchPrinterImpl; useHeaderSeparator(useHeaderSeparator: boolean): TinybenchPrinterImpl; useRowSeparator(useRowSeparator: boolean): TinybenchPrinterImpl; prepareTableConfig(bench: Bench): { rows: Record<string, string>[]; columns: string[]; headerTitles: Record<string, string>; headerAlignments: Record<string, _monstermann_tables.Alignment>; headerStyles: Record<string, ("bold" | "dim" | "italic" | "underline" | "inverse" | "hidden" | "strikethrough" | "black" | "red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white" | "gray" | "bgBlack" | "bgRed" | "bgGreen" | "bgYellow" | "bgBlue" | "bgMagenta" | "bgCyan" | "bgWhite")[]>; columnAlignments: Record<string, _monstermann_tables.Alignment>; columnStyles: Record<string, ("bold" | "dim" | "italic" | "underline" | "inverse" | "hidden" | "strikethrough" | "black" | "red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white" | "gray" | "bgBlack" | "bgRed" | "bgGreen" | "bgYellow" | "bgBlue" | "bgMagenta" | "bgCyan" | "bgWhite")[]>; maxWidth?: number | undefined; stdout?: NodeJS.WriteStream | undefined; padding?: number | undefined; borders?: Borders | undefined; borderStyle?: ("bold" | "dim" | "italic" | "underline" | "inverse" | "hidden" | "strikethrough" | "black" | "red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white" | "gray" | "bgBlack" | "bgRed" | "bgGreen" | "bgYellow" | "bgBlue" | "bgMagenta" | "bgCyan" | "bgWhite")[] | undefined; useHeader?: boolean | undefined; useTopBorder?: boolean | undefined; useBottomBorder?: boolean | undefined; useLeftBorder?: boolean | undefined; useRightBorder?: boolean | undefined; useDividerBorder?: boolean | undefined; useHeaderSeparator?: boolean | undefined; useRowSeparator?: boolean | undefined; } | undefined; toCli(bench: Bench): string; toMarkdown(bench: Bench): string; } declare const tinybenchPrinter: TinybenchPrinter<DefaultColumn>; export { type Column, type ColumnContext, type ColumnOptions, type Columns, type CountMethod, type DefaultColumn, type DurationMethod, type MarginOptions, type NameOptions, type OpsOptions, type SamplesOptions, type SortMethod, type SummaryMethod, type SummaryOptions, type TaskWithResult, type TimeOptions, type TinybenchPrinter, TinybenchPrinterImpl, tinybenchPrinter };