+446
-264
| //#region src/task.d.ts | ||
| /** | ||
@@ -8,146 +7,171 @@ * A class that represents each benchmark task in Tinybench. It keeps track of the | ||
| declare class Task extends EventTarget { | ||
| #private; | ||
| addEventListener: <K extends TaskEvents>(type: K, listener: EventListener<K, 'task'> | EventListenerObject<K, 'task'> | null, options?: AddEventListenerOptionsArgument) => void; | ||
| removeEventListener: <K extends TaskEvents>(type: K, listener: EventListener<K, 'task'> | EventListenerObject<K, 'task'> | null, options?: RemoveEventListenerOptionsArgument) => void; | ||
| /** | ||
| * The task name | ||
| * The name of the task. | ||
| * @returns The task name as a string | ||
| */ | ||
| readonly name: string; | ||
| get name(): string; | ||
| /** | ||
| * The result object | ||
| * The result of the task. | ||
| * @returns The task result including state, statistics, and runtime information | ||
| */ | ||
| result: Readonly<TaskResult> | undefined; | ||
| get result(): TaskResult & TaskResultRuntimeInfo & TaskResultTimestampProviderInfo; | ||
| /** | ||
| * The number of times the task function has been executed | ||
| * The number of times the task function has been executed. | ||
| * @returns The total number of executions performed | ||
| */ | ||
| runs: number; | ||
| get runs(): number; | ||
| constructor(bench: BenchLike, name: string, fn: Fn, fnOpts?: FnOptions); | ||
| /** | ||
| * The task asynchronous status | ||
| * Resets the task to make the `Task.runs` a zero-value and remove the `Task.result` object property. | ||
| * @param emit - whether to emit the `reset` event or not | ||
| */ | ||
| private readonly async; | ||
| reset(emit?: boolean): void; | ||
| /** | ||
| * The Bench instance reference | ||
| */ | ||
| private readonly bench; | ||
| /** | ||
| * The task function | ||
| */ | ||
| private readonly fn; | ||
| /** | ||
| * The task function options | ||
| */ | ||
| private readonly fnOpts; | ||
| /** | ||
| * The task-level abort signal | ||
| */ | ||
| private readonly signal; | ||
| constructor(bench: Bench, name: string, fn: Fn, fnOpts?: FnOptions); | ||
| addEventListener<K extends TaskEvents>(type: K, listener: TaskEventsMap[K], options?: AddEventListenerOptionsArgument): void; | ||
| removeEventListener<K extends TaskEvents>(type: K, listener: TaskEventsMap[K], options?: RemoveEventListenerOptionsArgument): void; | ||
| /** | ||
| * reset the task to make the `Task.runs` a zero-value and remove the `Task.result` object property | ||
| * @internal | ||
| */ | ||
| reset(): void; | ||
| /** | ||
| * run the current task and write the results in `Task.result` object property | ||
| * Runs the current task and writes the results in `Task.result` object property. | ||
| * @returns the current task | ||
| * @internal | ||
| */ | ||
| run(): Promise<Task>; | ||
| /** | ||
| * run the current task and write the results in `Task.result` object property (sync version) | ||
| * Runs the current task synchronously and writes the results in `Task.result` object property. | ||
| * @returns the current task | ||
| * @internal | ||
| */ | ||
| runSync(): this; | ||
| /** | ||
| * warmup the current task | ||
| * @internal | ||
| * Warms up the current task. | ||
| */ | ||
| warmup(): Promise<void>; | ||
| /** | ||
| * warmup the current task (sync version) | ||
| * @internal | ||
| * Warms up the current task synchronously. | ||
| */ | ||
| warmupSync(): void; | ||
| private benchmark; | ||
| private benchmarkSync; | ||
| } | ||
| //#endregion | ||
| //#region src/event.d.ts | ||
| /** | ||
| * The BenchEvent class represents events that occur during the benchmarking | ||
| * process. | ||
| */ | ||
| declare class BenchEvent<K extends BenchEvents = BenchEvents, M extends 'bench' | 'task' = 'bench'> extends globalThis.Event { | ||
| #private; | ||
| type: K; | ||
| /** | ||
| * Check if either our signal or the bench-level signal is aborted | ||
| * @returns `true` if either signal is aborted | ||
| * The error associated with the event. | ||
| * @returns The error if the event type is one that includes an error; otherwise, undefined | ||
| */ | ||
| private isAborted; | ||
| private measureOnce; | ||
| private measureOnceSync; | ||
| get error(): K extends BenchEventsWithError ? Error : undefined; | ||
| /** | ||
| * merge into the result object values | ||
| * @param result - the task result object to merge with the current result object values | ||
| * The task associated with the event. | ||
| * @returns The task if the event type is one that includes a task; otherwise, undefined | ||
| */ | ||
| private mergeTaskResult; | ||
| private postWarmup; | ||
| private processRunResult; | ||
| get task(): M extends 'task' ? Task : K extends BenchEventsWithTask ? Task : undefined; | ||
| constructor(type: BenchEventsWithError, task: Task, error: Error); | ||
| constructor(type: BenchEventsWithTask, task: Task); | ||
| constructor(type: BenchEventsOptionalTask, task?: Task); | ||
| } | ||
| //#endregion | ||
| //#region src/utils.d.ts | ||
| //#region src/types.d.ts | ||
| /** | ||
| * The JavaScript runtime environment. | ||
| * @see https://runtime-keys.proposal.wintercg.org/ | ||
| * Options for adding an event listener | ||
| */ | ||
| declare enum JSRuntime { | ||
| browser = "browser", | ||
| bun = "bun", | ||
| deno = "deno", | ||
| 'edge-light' = "edge-light", | ||
| fastly = "fastly", | ||
| hermes = "hermes", | ||
| jsc = "jsc", | ||
| lagon = "lagon", | ||
| moddable = "moddable", | ||
| netlify = "netlify", | ||
| node = "node", | ||
| 'quickjs-ng' = "quickjs-ng", | ||
| spidermonkey = "spidermonkey", | ||
| v8 = "v8", | ||
| workerd = "workerd", | ||
| } | ||
| type AddEventListenerOptionsArgument = Parameters<typeof EventTarget.prototype.addEventListener>[2]; | ||
| /** | ||
| * Converts nanoseconds to milliseconds. | ||
| * @param ns - the nanoseconds to convert | ||
| * @returns the milliseconds | ||
| * Bench events | ||
| */ | ||
| declare const nToMs: (ns: number) => number; | ||
| type BenchEvents = 'abort' | 'add' | 'complete' | 'cycle' | 'error' | 'remove' | 'reset' | 'start' | 'warmup'; | ||
| /** | ||
| * Returns the current high resolution timestamp in milliseconds using `process.hrtime.bigint()`. | ||
| * @returns the current high resolution timestamp in milliseconds | ||
| * Bench events that may have an associated Task | ||
| */ | ||
| declare const hrtimeNow: () => number; | ||
| declare const now: () => number; | ||
| //#endregion | ||
| //#region src/types.d.ts | ||
| type AddEventListenerOptionsArgument = Parameters<typeof EventTarget.prototype.addEventListener>[2]; | ||
| type BenchEventsOptionalTask = Omit<BenchEvents, 'add' | 'cycle' | 'error' | 'remove'>; | ||
| /** | ||
| * Bench event | ||
| * Bench events that have an associated error | ||
| */ | ||
| type BenchEvent = Event & { | ||
| error?: Error; | ||
| task?: Task; | ||
| }; | ||
| type BenchEventsWithError = Extract<BenchEvents, 'error'>; | ||
| /** | ||
| * Bench events | ||
| * Bench events that have an associated Task | ||
| */ | ||
| type BenchEvents = 'abort' | 'add' | 'complete' | 'cycle' | 'error' | 'remove' | 'reset' | 'start' | 'warmup'; | ||
| interface BenchEventsMap { | ||
| abort: EventListener; | ||
| add: EventListener; | ||
| complete: EventListener; | ||
| cycle: EventListener; | ||
| error: EventListener; | ||
| remove: EventListener; | ||
| reset: EventListener; | ||
| start: EventListener; | ||
| warmup: EventListener; | ||
| } | ||
| type BenchEventsWithTask = Extract<BenchEvents, 'add' | 'cycle' | 'error' | 'remove'>; | ||
| /** | ||
| * Both the `Task` and `Bench` objects extend the `EventTarget` object. | ||
| * So you can attach a listeners to different types of events to each class instance | ||
| * using the universal `addEventListener` and `removeEventListener` methods. | ||
| * Used to decouple Bench and Task | ||
| */ | ||
| interface BenchLike extends EventTarget { | ||
| /** | ||
| * Adds a listener for the specified event type. | ||
| */ | ||
| addEventListener: <K extends BenchEvents>(type: K, listener: EventListener<K> | EventListenerObject<K> | null, options?: AddEventListenerOptionsArgument) => void; | ||
| /** | ||
| * Executes tasks concurrently based on the specified concurrency mode, if set. | ||
| * | ||
| * - When `mode` is set to `null` (default), concurrency is disabled. | ||
| * - When `mode` is set to 'task', each task's iterations (calls of a task function) run concurrently. | ||
| * - When `mode` is set to 'bench', different tasks within the bench run concurrently. | ||
| */ | ||
| concurrency: Concurrency; | ||
| /** | ||
| * The amount of executions per task. | ||
| */ | ||
| iterations: number; | ||
| /** | ||
| * A function to get a timestamp. | ||
| */ | ||
| now: NowFn; | ||
| /** | ||
| * Removes a previously registered event listener. | ||
| */ | ||
| removeEventListener: <K extends BenchEvents>(type: K, listener: EventListener<K> | EventListenerObject<K> | null, options?: RemoveEventListenerOptionsArgument) => void; | ||
| /** | ||
| * Should samples be retained for further custom processing | ||
| */ | ||
| retainSamples: boolean; | ||
| /** | ||
| * The JavaScript runtime environment. | ||
| */ | ||
| runtime: JSRuntime; | ||
| /** | ||
| * The JavaScript runtime version. | ||
| */ | ||
| runtimeVersion: string; | ||
| /** | ||
| * A setup function that runs before each task execution. | ||
| */ | ||
| setup: (task: Task, mode: 'run' | 'warmup') => Promise<void> | void; | ||
| /** | ||
| * An AbortSignal to cancel the benchmark | ||
| */ | ||
| signal?: AbortSignal; | ||
| /** | ||
| * A teardown function that runs after each task execution. | ||
| */ | ||
| teardown: (task: Task, mode: 'run' | 'warmup') => Promise<void> | void; | ||
| /** | ||
| * The maximum number of concurrent tasks to run | ||
| */ | ||
| threshold: number; | ||
| /** | ||
| * Whether to throw an error if a task function throws | ||
| */ | ||
| throws: boolean; | ||
| /** | ||
| * The amount of time to run each task. | ||
| */ | ||
| time: number; | ||
| /** | ||
| * The timestamp provider used by the benchmark. | ||
| */ | ||
| timestampProvider: TimestampProvider; | ||
| /** | ||
| * Whether to warmup the tasks before running them | ||
| */ | ||
| warmup: boolean; | ||
| /** | ||
| * The amount of warmup iterations per task. | ||
| */ | ||
| warmupIterations: number; | ||
| /** | ||
| * The amount of time to warmup each task. | ||
| */ | ||
| warmupTime: number; | ||
| } | ||
| /** | ||
@@ -158,43 +182,72 @@ * Bench options | ||
| /** | ||
| * number of times that a task should run if even the time option is finished @default 64 | ||
| * Executes tasks concurrently based on the specified concurrency mode. | ||
| * | ||
| * - When `mode` is set to `null` (default), concurrency is disabled. | ||
| * - When `mode` is set to 'task', each task's iterations (calls of a task function) run concurrently. | ||
| * - When `mode` is set to 'bench', different tasks within the bench run concurrently. | ||
| */ | ||
| concurrency?: Concurrency; | ||
| /** | ||
| * The number of times that a task should run if even the time option is finished. | ||
| * @default 64 | ||
| */ | ||
| iterations?: number; | ||
| /** | ||
| * benchmark name | ||
| * Benchmark name. | ||
| */ | ||
| name?: string; | ||
| /** | ||
| * function to get the current timestamp in milliseconds | ||
| * Function to get the current timestamp in milliseconds. | ||
| */ | ||
| now?: () => number; | ||
| now?: NowFn; | ||
| /** | ||
| * setup function to run before each benchmark task (cycle) | ||
| * Keep samples for statistics calculation | ||
| * @default false | ||
| */ | ||
| retainSamples?: boolean; | ||
| /** | ||
| * Setup function to run before each benchmark task (cycle) | ||
| */ | ||
| setup?: Hook; | ||
| /** | ||
| * An AbortSignal for aborting the benchmark | ||
| * An AbortSignal for aborting the benchmark. | ||
| */ | ||
| signal?: AbortSignal; | ||
| /** | ||
| * teardown function to run after each benchmark task (cycle) | ||
| * Teardown function to run after each benchmark task (cycle). | ||
| */ | ||
| teardown?: Hook; | ||
| /** | ||
| * Throws if a task fails @default false | ||
| * The maximum number of concurrent tasks to run | ||
| * @default Number.POSITIVE_INFINITY | ||
| */ | ||
| threshold?: number; | ||
| /** | ||
| * Throws if a task fails. | ||
| * @default false | ||
| */ | ||
| throws?: boolean; | ||
| /** | ||
| * time needed for running a benchmark task (milliseconds) @default 1000 | ||
| * Time needed for running a benchmark task in milliseconds. | ||
| * @default 1000 | ||
| */ | ||
| time?: number; | ||
| /** | ||
| * warmup benchmark @default true | ||
| * The timestamp provider used by the benchmark. By default 'performance.now' | ||
| * will be used. | ||
| */ | ||
| timestampProvider?: TimestampFns | TimestampProvider; | ||
| /** | ||
| * Warmup benchmark. | ||
| * @default true | ||
| */ | ||
| warmup?: boolean; | ||
| /** | ||
| * warmup iterations @default 16 | ||
| * Warmup iterations. | ||
| * @default 16 | ||
| */ | ||
| warmupIterations?: number; | ||
| /** | ||
| * warmup time (milliseconds) @default 250 | ||
| * Warmup time in milliseconds. | ||
| * @default 250 | ||
| */ | ||
@@ -204,6 +257,27 @@ warmupTime?: number; | ||
| /** | ||
| * - When `mode` is set to `null` (default), concurrency is disabled. | ||
| * - When `mode` is set to 'task', each task's iterations (calls of a task function) run concurrently. | ||
| * - When `mode` is set to 'bench', different tasks within the bench run concurrently. | ||
| */ | ||
| type Concurrency = 'bench' | 'task' | null; | ||
| /** | ||
| * Converts a Task to a console.table friendly object | ||
| */ | ||
| type ConsoleTableConverter = (task: Task) => Record<string, number | string>; | ||
| /** | ||
| * Event listener | ||
| */ | ||
| type EventListener = (evt: BenchEvent) => void; | ||
| type EventListener<E extends BenchEvents, M extends 'bench' | 'task' = 'bench'> = (evt: BenchEvent<E, M>) => void; | ||
| /** | ||
| * Both the `Task` and `Bench` objects extend the `EventTarget` object. | ||
| * So you can attach a listeners to different types of events to each class instance | ||
| * using the universal `addEventListener` and `removeEventListener` methods. | ||
| */ | ||
| interface EventListenerObject<E extends BenchEvents, M extends 'bench' | 'task' = 'bench'> { | ||
| /** | ||
| * A method called when the event is dispatched. | ||
| */ | ||
| handleEvent(evt: BenchEvent<E, M>): void; | ||
| } | ||
| /** | ||
| * The task function. | ||
@@ -236,2 +310,7 @@ * | ||
| /** | ||
| * Whether the provided task function is asynchronous, otherwise it is | ||
| * determined automatically. | ||
| */ | ||
| async?: boolean; | ||
| /** | ||
| * An optional function that is run before iterations of this task begin | ||
@@ -245,2 +324,6 @@ */ | ||
| /** | ||
| * Retain samples for this task, overriding the bench-level retainSamples option | ||
| */ | ||
| retainSamples?: boolean; | ||
| /** | ||
| * An AbortSignal for aborting this specific task | ||
@@ -273,3 +356,16 @@ * | ||
| type Hook = (task?: Task, mode?: 'run' | 'warmup') => Promise<void> | void; | ||
| /** | ||
| * The JavaScript runtime environment. | ||
| * @see https://runtime-keys.proposal.wintercg.org/ | ||
| */ | ||
| type JSRuntime = 'browser' | 'bun' | 'deno' | 'edge-light' | 'fastly' | 'hermes' | 'jsc' | 'lagon' | 'moddable' | 'netlify' | 'node' | 'quickjs-ng' | 'spidermonkey' | 'unknown' | 'v8' | 'workerd'; | ||
| /** | ||
| /** | ||
| * A function that returns the current timestamp. | ||
| */ | ||
| type NowFn = () => number; | ||
| type RemoveEventListenerOptionsArgument = Parameters<typeof EventTarget.prototype.removeEventListener>[2]; | ||
| /** | ||
| * The resolved benchmark options | ||
| */ | ||
| interface ResolvedBenchOptions extends BenchOptions { | ||
@@ -287,2 +383,15 @@ iterations: NonNullable<BenchOptions['iterations']>; | ||
| /** | ||
| * A type representing a samples-array with at least one number. | ||
| */ | ||
| type Samples = [number, ...number[]]; | ||
| /** | ||
| * A type representing a sorted samples-array with at least one number. | ||
| */ | ||
| type SortedSamples = Samples & { | ||
| /** | ||
| * A unique symbol to identify sorted samples | ||
| */ | ||
| readonly __sorted__: unique symbol; | ||
| }; | ||
| /** | ||
| * The statistics object | ||
@@ -294,3 +403,3 @@ */ | ||
| */ | ||
| aad: number | undefined; | ||
| aad: number; | ||
| /** | ||
@@ -307,3 +416,3 @@ * critical value | ||
| */ | ||
| mad: number | undefined; | ||
| mad: number; | ||
| /** | ||
@@ -328,19 +437,19 @@ * the maximum value | ||
| */ | ||
| p50: number | undefined; | ||
| p50: number; | ||
| /** | ||
| * p75 percentile | ||
| */ | ||
| p75: number | undefined; | ||
| p75: number; | ||
| /** | ||
| * p99 percentile | ||
| */ | ||
| p99: number | undefined; | ||
| p99: number; | ||
| /** | ||
| * p995 percentile | ||
| */ | ||
| p995: number | undefined; | ||
| p995: number; | ||
| /** | ||
| * p999 percentile | ||
| */ | ||
| p999: number | undefined; | ||
| p999: number; | ||
| /** | ||
@@ -351,6 +460,10 @@ * relative margin of error | ||
| /** | ||
| * samples | ||
| * samples used to calculate the statistics | ||
| */ | ||
| samples: number[]; | ||
| samples: SortedSamples | undefined; | ||
| /** | ||
| * samples count | ||
| */ | ||
| samplesCount: number; | ||
| /** | ||
| * standard deviation | ||
@@ -371,84 +484,100 @@ */ | ||
| */ | ||
| type TaskEvents = 'abort' | 'complete' | 'cycle' | 'error' | 'reset' | 'start' | 'warmup'; | ||
| interface TaskEventsMap { | ||
| abort: EventListener; | ||
| complete: EventListener; | ||
| cycle: EventListener; | ||
| error: EventListener; | ||
| reset: EventListener; | ||
| start: EventListener; | ||
| warmup: EventListener; | ||
| } | ||
| type TaskEvents = Extract<BenchEvents, 'abort' | 'complete' | 'cycle' | 'error' | 'reset' | 'start' | 'warmup'>; | ||
| /** | ||
| * The task result object | ||
| * The task result | ||
| */ | ||
| interface TaskResult { | ||
| type TaskResult = TaskResultAborted | TaskResultAbortedWithStatistics | TaskResultCompleted | TaskResultErrored | TaskResultNotStarted | TaskResultStarted; | ||
| /** | ||
| * The task result for aborted tasks. | ||
| */ | ||
| interface TaskResultAborted { | ||
| /** | ||
| * whether the task was aborted | ||
| * the task state | ||
| */ | ||
| aborted: boolean; | ||
| state: 'aborted'; | ||
| } | ||
| /** | ||
| * The task result for aborted tasks, having also statistical data. | ||
| */ | ||
| interface TaskResultAbortedWithStatistics extends TaskResultWithStatistics { | ||
| /** | ||
| * the latency samples critical value | ||
| * @deprecated use `.latency.critical` instead | ||
| * the task state | ||
| */ | ||
| critical: number; | ||
| state: 'aborted-with-statistics'; | ||
| } | ||
| /** | ||
| * The task result for completed tasks with statistical data. | ||
| */ | ||
| interface TaskResultCompleted extends TaskResultWithStatistics { | ||
| /** | ||
| * the latency samples degrees of freedom | ||
| * @deprecated use `.latency.df` instead | ||
| * how long each operation takes (ms) | ||
| */ | ||
| df: number; | ||
| period: number; | ||
| /** | ||
| * the last task error that was thrown | ||
| * the task state | ||
| */ | ||
| error?: Error; | ||
| state: 'completed'; | ||
| } | ||
| /** | ||
| * The task result for errored tasks | ||
| */ | ||
| interface TaskResultErrored { | ||
| /** | ||
| * the number of operations per second | ||
| * @deprecated use `.throughput.mean` instead | ||
| * the error that caused the task to fail | ||
| */ | ||
| hz: number; | ||
| error: Error; | ||
| /** | ||
| * the task latency statistics | ||
| * the task state | ||
| */ | ||
| latency: Statistics; | ||
| state: 'errored'; | ||
| } | ||
| /** | ||
| * The task result for not started tasks | ||
| */ | ||
| interface TaskResultNotStarted { | ||
| /** | ||
| * the maximum latency samples value | ||
| * @deprecated use `.latency.max` instead | ||
| * the task state | ||
| */ | ||
| max: number; | ||
| state: 'not-started'; | ||
| } | ||
| /** | ||
| * The additional runtime information for task results | ||
| */ | ||
| interface TaskResultRuntimeInfo { | ||
| /** | ||
| * the latency samples mean/average | ||
| * @deprecated use `.latency.mean` instead | ||
| * the JavaScript runtime environment | ||
| */ | ||
| mean: number; | ||
| runtime: JSRuntime; | ||
| /** | ||
| * the minimum latency samples value | ||
| * @deprecated use `.latency.min` instead | ||
| * the JavaScript runtime version | ||
| */ | ||
| min: number; | ||
| runtimeVersion: string; | ||
| } | ||
| /** | ||
| * The task result for started tasks | ||
| */ | ||
| interface TaskResultStarted { | ||
| /** | ||
| * the latency samples margin of error | ||
| * @deprecated use `.latency.moe` instead | ||
| * the task state | ||
| */ | ||
| moe: number; | ||
| state: 'started'; | ||
| } | ||
| /** | ||
| * The timestamp provider information for task results | ||
| */ | ||
| interface TaskResultTimestampProviderInfo { | ||
| /** | ||
| * the latency samples p75 percentile | ||
| * @deprecated use `.latency.p75` instead | ||
| * the name of the timestamp provider used during the benchmark | ||
| */ | ||
| p75: number; | ||
| timestampProviderName: (string & {}) | TimestampFns; | ||
| } | ||
| /** | ||
| * The statistical data for task results | ||
| */ | ||
| interface TaskResultWithStatistics { | ||
| /** | ||
| * the latency samples p99 percentile | ||
| * @deprecated use `.latency.p99` instead | ||
| * the task latency statistics | ||
| */ | ||
| p99: number; | ||
| latency: Statistics; | ||
| /** | ||
| * the latency samples p995 percentile | ||
| * @deprecated use `.latency.p995` instead | ||
| */ | ||
| p995: number; | ||
| /** | ||
| * the latency samples p999 percentile | ||
| * @deprecated use `.latency.p999` instead | ||
| */ | ||
| p999: number; | ||
| /** | ||
| * how long each operation takes (ms) | ||
@@ -458,43 +587,51 @@ */ | ||
| /** | ||
| * the latency samples relative margin of error | ||
| * @deprecated use `.latency.rme` instead | ||
| * the task throughput statistics | ||
| */ | ||
| rme: number; | ||
| throughput: Statistics; | ||
| /** | ||
| * the JavaScript runtime environment | ||
| * the time to run the task benchmark cycle (ms) | ||
| */ | ||
| runtime: 'unknown' | JSRuntime; | ||
| totalTime: number; | ||
| } | ||
| /** | ||
| * A timestamp function that returns either a number or bigint. | ||
| */ | ||
| type TimestampFn = () => TimestampValue; | ||
| /** | ||
| * Possible timestamp provider names. | ||
| * 'custom' is used when a custom timestamp function is provided. | ||
| */ | ||
| type TimestampFns = 'auto' | 'bunNanoseconds' | 'custom' | 'hrtimeNow' | 'performanceNow'; | ||
| /** | ||
| * A timestamp provider and its related functions. | ||
| */ | ||
| interface TimestampProvider { | ||
| /** | ||
| * the JavaScript runtime version | ||
| * The actual function of the timestamp provider. | ||
| * @returns the timestamp value | ||
| */ | ||
| runtimeVersion: string; | ||
| fn: TimestampFn; | ||
| /** | ||
| * latency samples (ms) | ||
| * @deprecated use `.latency.samples` instead | ||
| * Converts milliseconds to the timestamp value. | ||
| * @param value - the milliseconds value | ||
| * @returns the timestamp value | ||
| */ | ||
| samples: number[]; | ||
| fromMs: (value: number) => TimestampValue; | ||
| /** | ||
| * the latency samples standard deviation | ||
| * @deprecated use `.latency.sd` instead | ||
| * The name of the timestamp provider. | ||
| */ | ||
| sd: number; | ||
| name: (string & {}) | TimestampFns; | ||
| /** | ||
| * the latency standard error of the mean (a.k.a. the standard deviation of the distribution of the sample mean/average) | ||
| * @deprecated use `.latency.sem` instead | ||
| * Converts the timestamp value to milliseconds. | ||
| * @param value - the timestamp value | ||
| * @returns the milliseconds | ||
| */ | ||
| sem: number; | ||
| /** | ||
| * the task throughput statistics | ||
| */ | ||
| throughput: Statistics; | ||
| /** | ||
| * the time to run the task benchmark cycle (ms) | ||
| */ | ||
| totalTime: number; | ||
| /** | ||
| * the latency samples variance | ||
| * @deprecated use `.latency.variance` instead | ||
| */ | ||
| variance: number; | ||
| toMs: (value: TimestampValue) => number; | ||
| } | ||
| /** | ||
| * A timestamp value, either number or bigint. Internally timestamps can use | ||
| * either representation depending on the environment and the chosen timestamp | ||
| * function. | ||
| */ | ||
| type TimestampValue = bigint | number; | ||
| //#endregion | ||
@@ -505,3 +642,5 @@ //#region src/bench.d.ts | ||
| */ | ||
| declare class Bench extends EventTarget { | ||
| declare class Bench extends EventTarget implements BenchLike { | ||
| #private; | ||
| addEventListener: <K extends BenchEvents>(type: K, listener: EventListener<K> | EventListenerObject<K> | null, options?: AddEventListenerOptionsArgument) => void; | ||
| /** | ||
@@ -514,15 +653,24 @@ * Executes tasks concurrently based on the specified concurrency mode. | ||
| */ | ||
| concurrency: 'bench' | 'task' | null; | ||
| readonly concurrency: 'bench' | 'task' | null; | ||
| /** | ||
| * The amount of executions per task. | ||
| */ | ||
| readonly iterations: number; | ||
| /** | ||
| * The benchmark name. | ||
| */ | ||
| readonly name?: string; | ||
| readonly name: string | undefined; | ||
| /** | ||
| * The options. | ||
| * A function to get a timestamp. | ||
| */ | ||
| readonly opts: Readonly<ResolvedBenchOptions>; | ||
| readonly now: () => number; | ||
| /** | ||
| * Removes a previously registered event listener. | ||
| */ | ||
| removeEventListener: <K extends BenchEvents>(type: K, listener: EventListener<K> | EventListenerObject<K> | null, options?: RemoveEventListenerOptionsArgument) => void; | ||
| readonly retainSamples: boolean; | ||
| /** | ||
| * The JavaScript runtime environment. | ||
| */ | ||
| readonly runtime: 'unknown' | JSRuntime; | ||
| readonly runtime: JSRuntime; | ||
| /** | ||
@@ -533,22 +681,56 @@ * The JavaScript runtime version. | ||
| /** | ||
| * The maximum number of concurrent tasks to run @default Number.POSITIVE_INFINITY | ||
| * A setup function that runs before each task execution. | ||
| */ | ||
| threshold: number; | ||
| readonly setup: (task: Task, mode: 'run' | 'warmup') => Promise<void> | void; | ||
| /** | ||
| * tasks results as an array | ||
| * @returns the tasks results as an array | ||
| * An AbortSignal to cancel the benchmark. | ||
| */ | ||
| get results(): (Readonly<TaskResult> | undefined)[]; | ||
| readonly signal: AbortSignal | undefined; | ||
| /** | ||
| * tasks as an array | ||
| * @returns the tasks as an array | ||
| * A teardown function that runs after each task execution. | ||
| */ | ||
| get tasks(): Task[]; | ||
| readonly teardown: (task: Task, mode: 'run' | 'warmup') => Promise<void> | void; | ||
| /** | ||
| * the task map | ||
| * The maximum number of concurrent tasks to run | ||
| * @default Number.POSITIVE_INFINITY | ||
| */ | ||
| private readonly _tasks; | ||
| readonly threshold: number; | ||
| /** | ||
| * Whether to throw an error if a task function throws | ||
| * @default false | ||
| */ | ||
| readonly throws: boolean; | ||
| /** | ||
| * The amount of time to run each task. | ||
| */ | ||
| readonly time: number; | ||
| /** | ||
| * A timestamp provider and its related functions. | ||
| */ | ||
| readonly timestampProvider: TimestampProvider; | ||
| /** | ||
| * Whether to warmup the tasks before running them | ||
| */ | ||
| readonly warmup: boolean; | ||
| /** | ||
| * The amount of warmup iterations per task. | ||
| */ | ||
| readonly warmupIterations: number; | ||
| /** | ||
| * The amount of time to warmup each task. | ||
| */ | ||
| readonly warmupTime: number; | ||
| /** | ||
| * The tasks results as an array. | ||
| * @returns the tasks results | ||
| */ | ||
| get results(): Readonly<TaskResult>[]; | ||
| /** | ||
| * The tasks as an array. | ||
| * @returns An array containing all benchmark tasks | ||
| */ | ||
| get tasks(): Task[]; | ||
| constructor(options?: BenchOptions); | ||
| /** | ||
| * add a benchmark task to the task map | ||
| * Adds a benchmark task to the task map. | ||
| * @param name - the task name | ||
@@ -558,14 +740,13 @@ * @param fn - the task function | ||
| * @returns the Bench instance | ||
| * @throws if the task already exists | ||
| * @throws {Error} when a task with the same name already exists | ||
| */ | ||
| add(name: string, fn: Fn, fnOpts?: FnOptions): this; | ||
| addEventListener<K extends BenchEvents>(type: K, listener: BenchEventsMap[K], options?: AddEventListenerOptionsArgument): void; | ||
| /** | ||
| * get a task based on the task name | ||
| * Gets a task based on the task name. | ||
| * @param name - the task name | ||
| * @returns the Task instance | ||
| * @returns the Task instance or undefined if not found | ||
| */ | ||
| getTask(name: string): Task | undefined; | ||
| /** | ||
| * remove a benchmark task from the task map | ||
| * Removes a benchmark task from the task map. | ||
| * @param name - the task name | ||
@@ -575,9 +756,8 @@ * @returns the Bench instance | ||
| remove(name: string): this; | ||
| removeEventListener<K extends BenchEvents>(type: K, listener: BenchEventsMap[K], options?: RemoveEventListenerOptionsArgument): void; | ||
| /** | ||
| * reset tasks and remove their result | ||
| * Resets all tasks and removes their results. | ||
| */ | ||
| reset(): void; | ||
| /** | ||
| * run the added tasks that were registered using the {@link add} method | ||
| * Runs the added benchmark tasks. | ||
| * @returns the tasks array | ||
@@ -587,3 +767,3 @@ */ | ||
| /** | ||
| * run the added tasks that were registered using the {@link add} method (sync version) | ||
| * Runs the added benchmark tasks synchronously. | ||
| * @returns the tasks array | ||
@@ -593,33 +773,35 @@ */ | ||
| /** | ||
| * table of the tasks results | ||
| * Returns the tasks results as a table. | ||
| * @param convert - an optional callback to convert the task result to a table record | ||
| * @returns the tasks results as an array of table records | ||
| */ | ||
| table(convert?: (task: Task) => Record<string, number | string | undefined>): (null | Record<string, number | string | undefined>)[]; | ||
| /** | ||
| * Applies a worker function to all registered tasks using the concurrency limit. | ||
| * | ||
| * Scheduling is handled via p-limit with the current threshold. The returned array preserves | ||
| * the iteration order of the tasks. If any scheduled worker function rejects, the returned promise | ||
| * rejects with the first error after the scheduled worker functions settle, as per Promise.all semantics. | ||
| * | ||
| * Notes: | ||
| * - Concurrency is controlled by Bench.threshold (Number.POSITIVE_INFINITY means unlimited). | ||
| * - No measurements are performed here; measurements happen inside Task. | ||
| * - Used internally by run() and warmupTasks() when concurrency === 'bench'. | ||
| * @template R The resolved type produced by the worker function for each task. | ||
| * @param workerFn A function invoked for each Task; it must return a Promise<R>. | ||
| * @returns Promise that resolves to an array of results in the same order as task iteration. | ||
| */ | ||
| private mapTasksConcurrently; | ||
| /** | ||
| * warmup the benchmark tasks. | ||
| */ | ||
| private warmupTasks; | ||
| /** | ||
| * warmup the benchmark tasks (sync version) | ||
| */ | ||
| private warmupTasksSync; | ||
| table(convert?: ConsoleTableConverter): (null | Record<string, number | string | undefined>)[]; | ||
| } | ||
| //#endregion | ||
| export { Bench, type BenchEvent, type BenchEvents, type BenchEventsMap, type BenchOptions, type EventListener, type Fn, type FnHook, type FnOptions, type FnReturnedObject, type Hook, type JSRuntime, type ResolvedBenchOptions, type Statistics, Task, type TaskEvents, type TaskEventsMap, type TaskResult, hrtimeNow, nToMs, now }; | ||
| //#region src/utils.d.ts | ||
| /** | ||
| * Converts nanoseconds to milliseconds. | ||
| * @param ns - the nanoseconds to convert | ||
| * @returns the milliseconds | ||
| */ | ||
| declare const nToMs: (ns: TimestampValue) => number; | ||
| /** | ||
| * Formats a number with the specified significant digits and maximum fraction digits. | ||
| * @param value - the number to format | ||
| * @param significantDigits - the number of significant digits in the output to aim for | ||
| * @param maxFractionDigits - hard limit for the number of digits after the decimal dot | ||
| * @returns the formatted number | ||
| */ | ||
| declare const formatNumber: (value: number, significantDigits?: number, maxFractionDigits?: number) => string; | ||
| /** | ||
| * Returns the current timestamp in milliseconds using `performance.now()`. | ||
| * @returns the current timestamp in milliseconds | ||
| */ | ||
| declare const performanceNow: () => DOMHighResTimeStamp; | ||
| /** | ||
| * Returns the current timestamp in milliseconds using `process.hrtime.bigint()`. | ||
| * @returns the current timestamp in milliseconds | ||
| */ | ||
| declare const hrtimeNow: () => number; | ||
| //#endregion | ||
| export { Bench, type BenchEvent, type BenchEvents, type BenchEventsWithTask, type BenchLike, type BenchOptions, type Concurrency, type ConsoleTableConverter, type EventListener, type EventListenerObject, type Fn, type FnHook, type FnOptions, type FnReturnedObject, type Hook, type JSRuntime, type NowFn, type ResolvedBenchOptions, type Samples, type SortedSamples, type Statistics, Task, type TaskEvents, type TaskResult, type TaskResultAborted, type TaskResultAbortedWithStatistics, type TaskResultCompleted, type TaskResultErrored, type TaskResultNotStarted, type TaskResultRuntimeInfo, type TaskResultStarted, type TaskResultTimestampProviderInfo, type TaskResultWithStatistics, type TimestampFn, type TimestampFns, type TimestampProvider, type TimestampValue, formatNumber, hrtimeNow, nToMs, performanceNow as now }; |
+1
-1
@@ -1,1 +0,1 @@ | ||
| var Node=class{value;next;constructor(u){this.value=u}},Queue=class{#head;#tail;#size;constructor(){this.clear()}enqueue(F){let I=new Node(F);this.#head?(this.#tail.next=I,this.#tail=I):(this.#head=I,this.#tail=I),this.#size++}dequeue(){let u=this.#head;if(u)return this.#head=this.#head.next,this.#size--,u.value}peek(){if(this.#head)return this.#head.value}clear(){this.#head=void 0,this.#tail=void 0,this.#size=0}get size(){return this.#size}*[Symbol.iterator](){let u=this.#head;for(;u;)yield u.value,u=u.next}*drain(){for(;this.#head;)yield this.dequeue()}};function pLimit(u){validateConcurrency(u);let I=new Queue,R=0,z=()=>{R<u&&I.size>0&&(R++,I.dequeue()())},B=()=>{R--,z()},V=async(u,F,I)=>{let L=(async()=>u(...I))();F(L);try{await L}catch{}B()},H=(F,L,B)=>{new Promise(u=>{I.enqueue(u)}).then(V.bind(void 0,F,L,B)),R<u&&z()},U=(u,...F)=>new Promise(I=>{H(u,I,F)});return Object.defineProperties(U,{activeCount:{get:()=>R},pendingCount:{get:()=>I.size},clearQueue:{value(){I.clear()}},concurrency:{get:()=>u,set(F){validateConcurrency(F),u=F,queueMicrotask(()=>{for(;R<u&&I.size>0;)z()})}},map:{async value(u,F){let I=Array.from(u,(u,I)=>this(F,u,I));return Promise.all(I)}}}),U}function validateConcurrency(u){if(!((Number.isInteger(u)||u===1/0)&&u>0))throw TypeError("Expected `concurrency` to be a number from 1 and up")}const tTable=Object.freeze({1:12.706204736432102,2:4.3026527299112765,3:3.182446305284264,4:2.7764451051977996,5:2.57058183661474,6:2.446911848791681,7:2.3646242510102997,8:2.306004135033371,9:2.262157162740992,10:2.2281388519649385,11:2.200985160082949,12:2.178812829663418,13:2.160368656461013,14:2.1447866879169277,15:2.131449545559323,16:2.1199052992210112,17:2.109815577833181,18:2.10092204024096,19:2.0930240544082634,20:2.085963447265837,21:2.0796138447276626,22:2.073873067904015,23:2.068657610419041,24:2.063898561628021,25:2.0595385527532946,26:2.0555294386428713,27:2.0518305164802837,28:2.048407141795244,29:2.0452296421327034,30:2.042272456301238,31:2.0395134463964077,32:2.0369333434601016,33:2.0345152974493383,34:2.0322445093177186,35:2.030107928250343,36:2.0280940009804507,37:2.0261924630291097,38:2.0243941645751367,39:2.0226909117347285,40:2.021075382995338,41:2.019540963982894,42:2.0180816970958815,43:2.0166921941428138,44:2.0153675699129416,45:2.0141033848332928,46:2.012895595294589,47:2.011740510475755,48:2.010634754696446,49:2.0095752344892093,50:2.0085591097152062,51:2.0075837681558824,52:2.0066468031022118,53:2.00574599353695,54:2.0048792865665233,55:2.0040447818101814,56:2.003240717496698,57:2.002465458054599,58:2.0017174830120927,59:2.0009953770482105,60:2.000297821058262,61:1.9996235841149783,62:1.9989715162223116,63:1.998340541772196,64:1.9977296536259739,65:1.9971379077520126,66:1.9965644183594748,67:1.996008353475506,68:1.9954689309194023,69:1.994945414632814,70:1.9944371113297732,71:1.9939433674345044,72:1.9934635662785831,73:1.9929971255321668,74:1.9925434948468204,75:1.9921021536898658,76:1.9916726093523491,77:1.9912543951146042,78:1.9908470685550523,79:1.9904502099893606,80:1.9900634210283845,81:1.9896863232444832,82:1.989318556936819,83:1.9889597799871794,84:1.9886096667986737,85:1.988267907310378,86:1.9879342060816723,87:1.9876082814405773,88:1.987289864690939,89:1.9869786993737681,90:1.9866745405784685,91:1.9863771543000652,92:1.9860863168388938,93:1.985801814239503,94:1.9855234417658303,95:1.9852510034099267,96:1.9849843114317696,97:1.9847231859278835,98:1.9844674544266925,99:1.9842169515086832,100:1.983971518449634,101:1.9837310028852815,102:1.9834952584959407,103:1.9832641447097104,104:1.9830375264229902,105:1.9828152737371547,106:1.9825972617102912,107:1.9823833701230178,108:1.9821734832574516,109:1.9819674896884745,110:1.9817652820865104,111:1.981566757031071,112:1.9813718148344008,113:1.9811803593745805,114:1.9809922979375068,115:1.9808075410672004,116:1.980626002423938,117:1.9804475986497296,118:1.9802722492407063,119:1.9800998764260065,120:1.979930405052777,121:1.9797637624769306,122:1.9795998784593314,123:1.97943868506709,124:1.979280116579683,125:1.9791241093996175,126:1.9789706019673938,127:1.978819534680521,128:1.9786708498163625,129:1.9785244914586055,130:1.9783804054271532,131:1.9782385392112587,132:1.9780988419057237,133:1.977961264150002,134:1.9778257580700531,135:1.9776922772228045,136:1.9775607765430836,137:1.977431212292894,138:1.9773035420129166,139:1.9771777244761224,140:1.9770537196433886,141:1.9769314886210223,142:1.97681099362009,143:1.9766921979174685,144:1.9765750658185368,145:1.9764595626214163,146:1.9763456545827007,147:1.9762333088845883,148:1.9761224936033637,149:1.9760131776791554,150:1.9759053308869141,151:1.9757989238085507,152:1.975693927806187,153:1.9755903149964589,154:1.9754880582258323,155:1.9753871310468787,156:1.9752875076954728,157:1.9751891630688665,158:1.9750920727046015,159:1.9749962127602256,160:1.9749015599937723,161:1.9748080917449764,162:1.9747157859171882,163:1.9746246209599583,164:1.9745345758522659,165:1.9744456300863593,166:1.9743577636521858,167:1.9742709570223849,168:1.974185191137821,169:1.9741004473936339,170:1.9740167076257829,171:1.9739339540980692,172:1.9738521694896138,173:1.9737713368827694,174:1.9736914397514562,175:1.9736124619498976,176:1.9735343877017435,177:1.9734572015895646,178:1.9733808885447033,179:1.9733054338374667,180:1.973230823067649,181:1.9731570421553692,182:1.9730840773322162,183:1.9730119151326795,184:1.9729405423858692,185:1.9728699462074992,186:1.9728001139921352,187:1.9727310334056907,188:1.9726626923781656,189:1.9725950790966158,190:1.9725281819983451,191:1.972461989764315,192:1.9723964913127596,193:1.9723316757930012,194:1.9722675325794565,195:1.972204051265833,196:1.9721412216594971,197:1.9720790337760221,198:1.972017477833896,199:1.9719565442493954,200:1.9718962236316093,201:1.9718365067776158,202:1.971777384667801,203:1.971718848461318,204:1.9716608894916787,205:1.971603499262479,206:1.9715466694432433,207:1.9714903918653972,208:1.9714346585183509,209:1.9713794615456992,210:1.9713247932415296,211:1.9712706460468354,212:1.9712170125460335,213:1.9711638854635767,214:1.971111257660664,215:1.9710591221320446,216:1.9710074720029072,217:1.97095630052586,218:1.9709056010779908,219:1.9708553671580111,220:1.9708055923834753,221:1.970756270488079,222:1.9707073953190282,223:1.9706589608344816,224:1.9706109611010594,225:1.9705633902914228,226:1.9705162426819125,227:1.9704695126502556,228:1.9704231946733297,229:1.9703772833249869,230:1.9703317732739336,231:1.9702866592816697,232:1.9702419362004757,233:1.9701975989714555,234:1.9701536426226303,235:1.9701100622670775,236:1.9700668531011214,237:1.9700240104025675,238:1.9699815295289818,239:1.969939405916016,240:1.9698976350757686,241:1.9698562125951948,242:1.9698151341345516,243:1.9697743954258797,244:1.9697339922715287,245:1.9696939205427133,246:1.9696541761781068,247:1.9696147551824699,248:1.9695756536253115,249:1.9695368676395828,250:1.9694983934204007,251:1.9694602272238055,252:1.9694223653655467,253:1.969384804219895,254:1.9693475402184863,255:1.9693105698491933,256:1.9692738896550193,257:1.9692374962330224,258:1.9692013862332616,259:1.9691655563577715,260:1.9691300033595551,261:1.9690947240416052,262:1.9690597152559448,263:1.9690249739026924,264:1.9689904969291443,265:1.968956281328883,266:1.9689223241409022,267:1.9688886224487527,268:1.9688551733797075,269:1.968821974103945,270:1.9687890218337525,271:1.968756313822743,272:1.968723847365097,273:1.9686916197948103,274:1.9686596284849691,275:1.9686278708470335,276:1.9685963443301415,277:1.968565046420423,278:1.9685339746403347,279:1.9685031265480044,280:1.9684724997365923,281:1.968442091833664,282:1.968411900500579,283:1.9683819234318907,284:1.9683521583547587,285:1.9683226030283762,286:1.9682932552434063,287:1.968264112821431,288:1.9682351736144144,289:1.9682064355041722,290:1.968177896401857,291:1.968149554247451,292:1.9681214070092705,293:1.9680934526834821,294:1.9680656892936232,295:1.968038114890141,296:1.9680107275499321,297:1.9679835253758984,298:1.967956506496507,299:1.9679296690653623,300:1.9679030112607847,301:1.9678765312853979,302:1.967850227365727,303:1.9678240977517998,304:1.967798140716761,305:1.9677723545564905,306:1.967746737589231,307:1.9677212881552217,308:1.967696004616341,309:1.967670885355754,310:1.9676459287775685,311:1.9676211333064957,312:1.9675964973875213,313:1.967572019485578,314:1.967547698085227,315:1.9675235316903468,316:1.9674995188238256,317:1.9674756580272583,318:1.9674519478606556,319:1.96742838690215,320:1.9674049737477135,321:1.9673817070108799,322:1.9673585853224684,323:1.9673356073303163,324:1.9673127716990173,325:1.9672900771096589,326:1.9672675222595717,327:1.9672451058620788,328:1.9672228266462515,329:1.9672006833566689,330:1.9671786747531816,331:1.9671567996106818,332:1.967135056718874,333:1.9671134448820529,334:1.9670919629188843,335:1.9670706096621893,336:1.967049383958733,337:1.9670282846690177,338:1.9670073106670771,339:1.9669864608402783,340:1.966965734089124,341:1.9669451293270586,342:1.9669246454802793,343:1.9669042814875488,344:1.9668840363000124,345:1.966863908881019,346:1.9668438982059417,347:1.966824003262006,348:1.9668042230481186,349:1.9667845565746986,350:1.9667650028635129,351:1.9667455609475144,352:1.9667262298706825,353:1.966707008687866,354:1.9666878964646288,355:1.9666688922770996,356:1.9666499952118222,357:1.9666312043656085,358:1.9666125188453965,359:1.9665939377681074,360:1.9665754602605063,361:1.9665570854590666,362:1.9665388125098342,363:1.966520640568296,364:1.9665025687992495,365:1.966484596376675,366:1.9664667224836099,367:1.9664489463120245,368:1.9664312670626998,369:1.9664136839451096,370:1.9663961961773,371:1.966378802985776,372:1.9663615036053859,373:1.9663442972792093,374:1.9663271832584475,375:1.9663101608023135,376:1.966293229177927,377:1.9662763876602067,378:1.96625963553177,379:1.9662429720828285,380:1.9662263966110878,381:1.9662099084216513,382:1.9661935068269203,383:1.9661771911465,384:1.9661609607071053,385:1.9661448148424667,386:1.9661287528932416,387:1.9661127742069229,388:1.9660968781377508,389:1.966081064046626,390:1.966065331301024,391:1.966049679274911,392:1.9660341073486605,393:1.9660186149089722,394:1.9660032013487905,395:1.9659878660672256,396:1.9659726084694753,397:1.9659574279667498,398:1.965942323976193,399:1.9659272959208094,400:1.9659123432293915,401:1.9658974653364458,402:1.9658826616821223,403:1.965867931712145,404:1.9658532748777406,405:1.9658386906355727,406:1.9658241784476738,407:1.965809737781378,408:1.9657953681092573,409:1.9657810689090576,410:1.9657668396636336,411:1.965752679860889,412:1.9657385889937122,413:1.9657245665599175,414:1.9657106120621863,415:1.9656967250080057,416:1.9656829049096134,417:1.9656691512839384,418:1.965655463652545,419:1.9656418415415793,420:1.9656282844817121,421:1.9656147920080864,422:1.9656013636602634,423:1.9655879989821707,424:1.9655746975220507,425:1.9655614588324102,426:1.965548282469968,427:1.9655351679956077,428:1.9655221149743287,429:1.9655091229751978,430:1.9654961915712998,431:1.9654833203396942,432:1.9654705088613673,433:1.9654577567211857,434:1.965445063507854,435:1.965432428813868,436:1.9654198522354724,437:1.9654073333726187,438:1.9653948718289207,439:1.9653824672116142,440:1.9653701191315152,441:1.9653578272029781,442:1.9653455910438589,443:1.9653334102754718,444:1.9653212845225516,445:1.9653092134132164,446:1.9652971965789277,447:1.9652852336544535,448:1.9652733242778317,449:1.9652614680903338,450:1.9652496647364275,451:1.9652379138637432,452:1.9652262151230366,453:1.9652145681681563,454:1.9652029726560083,455:1.9651914282465226,456:1.9651799346026202,457:1.9651684913901803,458:1.9651570982780076,459:1.9651457549378,460:1.9651344610441186,461:1.9651232162743548,462:1.9651120203087005,463:1.9651008728301178,464:1.9650897735243085,465:1.9650787220796855,466:1.9650677181873428,467:1.965056761541027,468:1.965045851837109,469:1.965034988774555,470:1.965024172054902,471:1.9650134013822251,472:1.9650026764631154,473:1.9649919970066518,474:1.9649813627243728,475:1.964970773330254,476:1.9649602285406784,477:1.9649497280744153,478:1.9649392716525922,479:1.964928858998672,480:1.9649184898384262,481:1.9649081638999137,482:1.9648978809134563,483:1.9648876406116125,484:1.9648774427291587,485:1.9648672870030628,486:1.9648571731724636,487:1.9648471009786466,488:1.9648370701650248,489:1.9648270804771135,490:1.9648171316625118,491:1.964807223470879,492:1.9647973556539153,493:1.9647875279653397,494:1.9647777401608706,495:1.9647679919982053,496:1.9647582832369994,497:1.9647486136388483,498:1.9647389829672652,499:1.9647293909876653,500:1.9647198374673442,501:1.9647103221754598,502:1.964700844883014,503:1.9646914053628335,504:1.9646820033895525,505:1.964672638739595,506:1.9646633111911553,507:1.9646540205241838,508:1.9646447665203655,509:1.964635548963106,510:1.9646263676375137,511:1.9646172223303833,512:1.9646081128301776,513:1.9645990389270147,514:1.9645900004126484,515:1.9645809970804544,516:1.9645720287254127,517:1.9645630951440949,518:1.964554196134645,519:1.9645453314967691,520:1.9645365010317148,521:1.9645277045422602,522:1.9645189418326983,523:1.964510212708822,524:1.964501516977911,525:1.964492854448715,526:1.9644842249314425,527:1.9644756282377454,528:1.9644670641807058,529:1.964458532574823,530:1.9644500332359982,531:1.9644415659815229,532:1.9644331306300662,533:1.9644247270016604,534:1.964416354917689,535:1.9644080142008735,536:1.9643997046752626,537:1.9643914261662165,538:1.9643831785003991,539:1.9643749615057613,540:1.9643667750115323,541:1.964358618848207,542:1.9643504928475335,543:1.964342396842502,544:1.9643343306673333,545:1.9643262941574684,546:1.9643182871495555,547:1.9643103094814403,548:1.964302360992155,549:1.9642944415219068,550:1.9642865509120675,551:1.9642786890051633,552:1.964270855644863,553:1.9642630506759702,554:1.9642552739444101,555:1.9642475252972216,556:1.9642398045825453,557:1.9642321116496164,558:1.9642244463487513,559:1.9642168085313412,560:1.9642091980498402,561:1.9642016147577568,562:1.964194058509645,563:1.9641865291610932,564:1.9641790265687171,565:1.964171550590149,566:1.9641641010840303,567:1.9641566779100006,568:1.9641492809286911,569:1.964141910001714,570:1.964134564991655,571:1.9641272457620647,572:1.9641199521774493,573:1.964112684103263,574:1.9641054414058998,575:1.9640982239526847,576:1.964091031611867,577:1.9640838642526093,578:1.964076721744983,579:1.9640696039599586,580:1.9640625107693983,581:1.9640554420460483,582:1.9640483976635308,583:1.9640413774963374,584:1.964034381419821,585:1.9640274093101877,586:1.9640204610444916,587:1.9640135365006257,588:1.9640066355573154,589:1.9639997580941106,590:1.963992903991381,591:1.9639860731303063,592:1.9639792653928712,593:1.9639724806618581,594:1.9639657188208401,595:1.9639589797541745,596:1.963952263346997,597:1.963945569485213,598:1.963938898055494,599:1.9639322489452695,600:1.96392562204272,601:1.9639190172367733,602:1.963912434417095,603:1.963905873474085,604:1.9638993342988706,605:1.9638928167832999,606:1.9638863208199362,607:1.9638798463020526,608:1.9638733931236256,609:1.9638669611793291,610:1.9638605503645292,611:1.9638541605752786,612:1.9638477917083106,613:1.963841443661033,614:1.9638351163315244,615:1.9638288096185263,616:1.9638225234214404,617:1.9638162576403206,618:1.96381001217587,619:1.9638037869294331,620:1.9637975818029945,621:1.9637913966991682,622:1.9637852315211985,623:1.9637790861729507,624:1.963772960558908,625:1.9637668545841658,626:1.9637607681544267,627:1.963754701175997,628:1.96374865355578,629:1.9637426252012729,630:1.9637366160205605,631:1.9637306259223126,632:1.9637246548157765,633:1.9637187026107747,634:1.9637127692177012,635:1.9637068545475131,636:1.9637009585117295,637:1.9636950810224274,638:1.9636892219922344,639:1.9636833813343266,640:1.963677558962424,641:1.9636717547907854,642:1.9636659687342057,643:1.96366020070801,644:1.9636544506280507,645:1.9636487184107032,646:1.9636430039728607,647:1.963637307231933,648:1.9636316281058388,649:1.9636259665130043,650:1.9636203223723585,651:1.9636146956033296,652:1.9636090861258415,653:1.9636034938603082,654:1.963597918727633,655:1.9635923606492014,656:1.9635868195468806,657:1.9635812953430134,658:1.9635757879604159,659:1.9635702973223736,660:1.9635648233526377,661:1.9635593659754214,662:1.9635539251153973,663:1.9635485006976923,664:1.9635430926478856,665:1.9635377008920054,666:1.9635323253565247,667:1.9635269659683576,668:1.9635216226548569,669:1.963516295343811,670:1.9635109839634397,671:1.9635056884423918,672:1.9635004087097414,673:1.9634951446949849,674:1.9634898963280374,675:1.9634846635392311,676:1.9634794462593101,677:1.9634742444194289,678:1.9634690579511493,679:1.9634638867864362,680:1.9634587308576554,681:1.9634535900975714,682:1.9634484644393435,683:1.9634433538165224,684:1.963438258163049,685:1.96343317741325,686:1.963428111501836,687:1.9634230603638985,688:1.9634180239349066,689:1.9634130021507055,690:1.9634079949475116,691:1.9634030022619122,692:1.9633980240308617,693:1.9633930601916791,694:1.963388110682045,695:1.9633831754399986,696:1.963378254403937,697:1.9633733475126116,698:1.9633684547051236,699:1.9633635759209254,700:1.9633587110998145,701:1.9633538601819331,702:1.9633490231077657,703:1.9633441998181338,704:1.9633393902541987,705:1.9633345943574538,706:1.9633298120697256,707:1.96332504333317,708:1.9633202880902698,709:1.9633155462838343,710:1.963310817856994,711:1.9633061027532,712:1.9633014009162226,713:1.9632967122901475,714:1.9632920368193745,715:1.963287374448614,716:1.9632827251228866,717:1.9632780887875207,718:1.9632734653881478,719:1.963268854870705,720:1.963264257181428,721:1.9632596722668525,722:1.9632551000738105,723:1.9632505405494287,724:1.963245993641126,725:1.963241459296613,726:1.9632369374638876,727:1.963232428091235,728:1.9632279311272245,729:1.963223446520709,730:1.9632189742208208,731:1.963214514176972,732:1.9632100663388516,733:1.9632056306564227,734:1.9632012070799227,735:1.9631967955598593,736:1.9631923960470097,737:1.9631880084924196,738:1.9631836328473993,739:1.9631792690635235,740:1.9631749170926298,741:1.9631705768868148,742:1.9631662483984351,743:1.9631619315801037,744:1.9631576263846882,745:1.9631533327653103,746:1.9631490506753435,747:1.963144780068411,748:1.963140520898385,749:1.9631362731193833,750:1.9631320366857699,751:1.9631278115521522,752:1.9631235976733785,753:1.9631193950045382,754:1.963115203500959,755:1.963111023118206,756:1.9631068538120793,757:1.963102695538613,758:1.963098548254074,759:1.963094411914959,760:1.963090286477995,761:1.9630861719001376,762:1.9630820681385661,763:1.963077975150687,764:1.963073892894129,765:1.9630698213267435,766:1.9630657604066017,767:1.9630617100919938,768:1.9630576703414275,769:1.9630536411136277,770:1.9630496223675324,771:1.963045614062295,772:1.963041616157278,773:1.9630376286120574,774:1.9630336513864166,775:1.9630296844403485,776:1.9630257277340504,777:1.9630217812279265,778:1.9630178448825841,779:1.963013918658834,780:1.9630100025176869,781:1.9630060964203544,782:1.9630022003282468,783:1.9629983142029712,784:1.9629944380063318,785:1.962990571700327,786:1.9629867152471494,787:1.9629828686091835,788:1.9629790317490055,789:1.962975204629381,790:1.9629713872132657,791:1.9629675794638015,792:1.962963781344317,793:1.9629599928183272,794:1.9629562138495296,795:1.9629524444018054,796:1.9629486844392179,797:1.9629449339260105,798:1.9629411928266058,799:1.962937461105606,800:1.9629337387277892,801:1.9629300256581104,802:1.9629263218616995,803:1.9629226273038602,804:1.9629189419500692,805:1.9629152657659752,806:1.9629115987173975,807:1.9629079407703247,808:1.9629042918909145,809:1.9629006520454917,810:1.9628970212005485,811:1.9628933993227415,812:1.9628897863788926,813:1.9628861823359869,814:1.962882587161172,815:1.9628790008217571,816:1.9628754232852115,817:1.9628718545191641,818:1.9628682944914029,819:1.9628647431698727,820:1.9628612005226753,821:1.9628576665180681,822:1.9628541411244633,823:1.9628506243104265,824:1.962847116044676,825:1.962843616296083,826:1.9628401250336684,827:1.9628366422266041,828:1.9628331678442101,829:1.962829701855956,830:1.9628262442314577,831:1.9628227949404782,832:1.9628193539529253,833:1.962815921238852,834:1.9628124967684557,835:1.962809080512076,836:1.9628056724401943,837:1.962802272523434,838:1.9627988807325591,839:1.9627954970384724,840:1.9627921214122162,841:1.96278875382497,842:1.9627853942480507,843:1.9627820426529121,844:1.9627786990111424,845:1.9627753632944653,846:1.962772035474738,847:1.962768715523951,848:1.962765403414227,849:1.9627620991178198,850:1.9627588026071152,851:1.9627555138546275,852:1.9627522328330012,853:1.962748959515009,854:1.962745693873551,855:1.9627424358816548,856:1.9627391855124732,857:1.9627359427392859,858:1.9627327075354966,859:1.9627294798746329,860:1.9627262597303463,861:1.9627230470764099,862:1.962719841886719,863:1.962716644135291,864:1.9627134537962623,865:1.9627102708438906,866:1.9627070952525512,867:1.9627039269967388,868:1.9627007660510651,869:1.9626976123902597,870:1.9626944659891674,871:1.9626913268227497,872:1.9626881948660826,873:1.9626850700943568,874:1.9626819524828756,875:1.9626788420070573,876:1.962675738642431,877:1.9626726423646375,878:1.9626695531494305,879:1.962666470972672,880:1.9626633958103352,881:1.9626603276385024,882:1.962657266433364,883:1.962654212171219,884:1.962651164828473,885:1.962648124381639,886:1.962645090807336,887:1.9626420640822897,888:1.9626390441833281,889:1.9626360310873863,890:1.9626330247715016,891:1.962630025212815,892:1.962627032388571,893:1.9626240462761142,894:1.9626210668528927,895:1.9626180940964544,896:1.9626151279844477,897:1.9626121684946207,898:1.9626092156048216,899:1.9626062692929966,900:1.9626033295371899,901:1.9626003963155434,902:1.9625974696062964,903:1.9625945493877848,904:1.9625916356384394,905:1.9625887283367882,906:1.9625858274614525,907:1.962582932991149,908:1.9625800449046875,909:1.9625771631809725,910:1.962574287799,911:1.9625714187378587,912:1.9625685559767294,913:1.9625656994948841,914:1.9625628492716856,915:1.9625600052865868,916:1.9625571675191313,917:1.9625543359489512,918:1.9625515105557676,919:1.9625486913193901,920:1.9625458782197165,921:1.9625430712367309,922:1.962540270350506,923:1.9625374755412,924:1.962534686789057,925:1.962531904074407,926:1.9625291273776646,927:1.96252635667933,928:1.9625235919599864,929:1.962520833200302,930:1.9625180803810265,931:1.962515333482994,932:1.9625125924871198,933:1.9625098573744026,934:1.9625071281259212,935:1.962504404722836,936:1.9625016871463874,937:1.9624989753778976,938:1.9624962693987664,939:1.9624935691904748,940:1.9624908747345817,941:1.9624881860127243,942:1.9624855030066184,943:1.9624828256980582,944:1.962480154068913,945:1.962477488101131,946:1.962474827776736,947:1.9624721730778274,948:1.962469523986581,949:1.9624668804852476,950:1.9624642425561525,951:1.962461610181696,952:1.9624589833443515,953:1.9624563620266673,954:1.9624537462112641,955:1.9624511358808356,956:1.9624485310181483,957:1.9624459316060407,958:1.9624433376274224,959:1.9624407490652758,960:1.9624381659026522,961:1.9624355881226763,962:1.962433015708541,963:1.9624304486435091,964:1.9624278869109137,965:1.9624253304941575,966:1.9624227793767104,967:1.9624202335421121,968:1.9624176929739703,969:1.9624151576559599,970:1.962412627571823,971:1.9624101027053702,972:1.9624075830404768,973:1.9624050685610865,974:1.962402559251207,975:1.9624000550949139,976:1.9623975560763454,977:1.962395062179708,978:1.9623925733892695,979:1.9623900896893647,980:1.9623876110643914,981:1.9623851374988106,982:1.9623826689771475,983:1.96238020548399,984:1.9623777470039887,985:1.962375293521857,986:1.9623728450223694,987:1.9623704014903631,988:1.9623679629107367,989:1.9623655292684494,990:1.9623631005485223,991:1.9623606767360353,992:1.9623582578161303,993:1.9623558437740083,994:1.9623534345949294,995:1.9623510302642144,996:1.9623486307672415,997:1.9623462360894495,998:1.962343846216334,999:1.962341461133449,1e3:1.9623390808264078,1001:1.9623367052808791,1002:1.9623343344825908,1003:1.962331968417326,1004:1.9623296070709262,1005:1.9623272504292881,1006:1.9623248984783654,1007:1.9623225512041673,1008:1.9623202085927578,1009:1.9623178706302578,1010:1.9623155373028418,1011:1.9623132085967403,1012:1.962310884498237,1013:1.962308564993671,1014:1.962306250069434,1015:1.9623039397119733,1016:1.9623016339077874,1017:1.9622993326434304,1018:1.962297035905507,1019:1.9622947436806755,1020:1.9622924559556474,1021:1.962290172717185,1022:1.9622878939521027,1023:1.9622856196472673,1024:1.962283349789597,infinity:1.96}),emptyFunction=Object.freeze(()=>{}),createBenchEvent=(u,F)=>{let I=new globalThis.Event(u);return F&&Object.defineProperty(I,`task`,{configurable:!1,enumerable:!1,value:F,writable:!1}),I},createErrorEvent=(u,F)=>{let I=new globalThis.Event(`error`);return Object.defineProperty(I,`task`,{configurable:!1,enumerable:!1,value:u,writable:!1}),Object.defineProperty(I,`error`,{configurable:!1,enumerable:!1,value:F,writable:!1}),I};let JSRuntime=function(u){return u.browser=`browser`,u.bun=`bun`,u.deno=`deno`,u[`edge-light`]=`edge-light`,u.fastly=`fastly`,u.hermes=`hermes`,u.jsc=`jsc`,u.lagon=`lagon`,u.moddable=`moddable`,u.netlify=`netlify`,u.node=`node`,u[`quickjs-ng`]=`quickjs-ng`,u.spidermonkey=`spidermonkey`,u.v8=`v8`,u.workerd=`workerd`,u}({});const isBun=!!globalThis.Bun||!!globalThis.process?.versions?.bun,isDeno=!!globalThis.Deno,isNode=globalThis.process?.release?.name===`node`,isHermes=!!globalThis.HermesInternal,isWorkerd=globalThis.navigator?.userAgent===`Cloudflare-Workers`,isQuickJsNg=!!globalThis.navigator?.userAgent?.toLowerCase?.()?.includes?.(`quickjs-ng`),isNetlify=typeof globalThis.Netlify==`object`,isEdgeLight=typeof globalThis.EdgeRuntime==`string`,isLagon=!!globalThis.__lagon__,isFastly=!!globalThis.fastly,isModdable=!!globalThis.$262&&!!globalThis.lockdown&&!!globalThis.AsyncDisposableStack,isV8=!!globalThis.d8,isSpiderMonkey=!!globalThis.inIon&&!!globalThis.performance?.mozMemory,isJsc=!!globalThis.$&&`IsHTMLDDA`in globalThis.$,isBrowser=!!globalThis.window&&!!globalThis.navigator,runtime=(()=>isBun?JSRuntime.bun:isDeno?JSRuntime.deno:isNode?JSRuntime.node:isHermes?JSRuntime.hermes:isNetlify?JSRuntime.netlify:isEdgeLight?JSRuntime[`edge-light`]:isLagon?JSRuntime.lagon:isFastly?JSRuntime.fastly:isWorkerd?JSRuntime.workerd:isQuickJsNg?JSRuntime[`quickjs-ng`]:isModdable?JSRuntime.moddable:isV8?JSRuntime.v8:isSpiderMonkey?JSRuntime.spidermonkey:isJsc?JSRuntime.jsc:isBrowser?JSRuntime.browser:`unknown`)(),runtimeVersion=(()=>runtime===JSRuntime.bun?globalThis.Bun?.version:runtime===JSRuntime.deno?globalThis.Deno?.version?.deno:runtime===JSRuntime.node?globalThis.process?.versions?.node:runtime===JSRuntime.hermes?globalThis.HermesInternal?.getRuntimeProperties?.()?.[`OSS Release Version`]:runtime===JSRuntime.v8?globalThis.version?.():runtime===JSRuntime[`quickjs-ng`]?globalThis.navigator?.userAgent?.split?.(`/`)[1]:`unknown`)(),nToMs=u=>u/1e6,mToNs=u=>u*1e6,formatNumber=(u,F,I)=>{if(typeof u!=`number`)return String(u);if(u===1/0)return`+∞`;if(u===-1/0)return`-∞`;if(Number.isNaN(u))return`NaN`;let L=Math.abs(u);if(L>=10**F)return u.toFixed();if(L<10**(F-I))return u.toFixed(I);let R=L>=1?Math.floor(Math.log10(L))+1:0,z=Math.max(0,F-R);return z=Math.min(z,I),u.toFixed(z)};let hrtimeBigint;hrtimeBigint=typeof globalThis.process?.hrtime?.bigint==`function`?globalThis.process.hrtime.bigint.bind(process.hrtime):()=>{throw Error(`hrtime.bigint() is not supported in this JS environment`)};const hrtimeNow=()=>nToMs(Number(hrtimeBigint())),now=performance.now.bind(performance),isPromiseLike=u=>u!==null&&(typeof u==`object`||typeof u==`function`)&&typeof u.then==`function`,isAsyncFunction=u=>u?.constructor===(async()=>{}).constructor,isFnAsyncResource=u=>{if(u==null)return!1;if(isAsyncFunction(u))return!0;try{let F=u(),I=isPromiseLike(F);if(I)try{F.then(emptyFunction)?.catch(emptyFunction)}catch{}return I}catch{return!1}},average=u=>{if(u.length===0)throw Error(`samples must not be empty`);return u.reduce((u,F)=>u+F,0)/u.length||0},variance=(u,F=average(u))=>u.length<=1?0:u.reduce((u,I)=>u+(I-F)**2,0)/(u.length-1),quantileSorted=(u,F)=>{if(u.length===0)throw Error(`samples must not be empty`);if(F<0||F>1)throw Error(`q must be between 0 and 1`);if(F===0)return u[0];if(F===1)return u[u.length-1];let I=(u.length-1)*F,L=Math.floor(I);return u[L+1]==null?u[L]:u[L]+(I-L)*(u[L+1]-u[L])},medianSorted=u=>quantileSorted(u,.5),median=u=>medianSorted([...u].sort((u,F)=>u-F)),absoluteDeviation=(u,F,I=F(u))=>{let L=[];for(let F of u)L.push(Math.abs(F-I));return F(L)},getStatisticsSorted=u=>{let F=average(u),I=variance(u,F),L=Math.sqrt(I),z=L/Math.sqrt(u.length),B=u.length-1,V=tTable[(Math.round(B)||1).toString()]||tTable.infinity,H=z*V,U=Math.abs(F),W=U===0?1/0:H/U*100,G=medianSorted(u);return{aad:absoluteDeviation(u,average,F),critical:V,df:B,mad:absoluteDeviation(u,median,G),max:u[B],mean:F,min:u[0],moe:H,p50:G,p75:quantileSorted(u,.75),p99:quantileSorted(u,.99),p995:quantileSorted(u,.995),p999:quantileSorted(u,.999),rme:W,samples:u,sd:L,sem:z,variance:I}},invariant=(u,F)=>{if(!u)throw Error(F)};var Task=class extends EventTarget{constructor(u,F,I,L={}){super(),this.runs=0,this.bench=u,this.name=F,this.fn=I,this.fnOpts=L,this.async=isFnAsyncResource(I),this.signal=L.signal,this.signal&&this.signal.addEventListener(`abort`,()=>{this.dispatchEvent(createBenchEvent(`abort`,this)),this.bench.dispatchEvent(createBenchEvent(`abort`,this))},{once:!0})}addEventListener(u,F,I){super.addEventListener(u,F,I)}removeEventListener(u,F,I){super.removeEventListener(u,F,I)}reset(){this.dispatchEvent(createBenchEvent(`reset`,this)),this.runs=0,this.result=void 0}async run(){if(this.result?.error)return this;this.dispatchEvent(createBenchEvent(`start`,this)),await this.bench.opts.setup(this,`run`);let{error:u,samples:F}=await this.benchmark(`run`,this.bench.opts.time,this.bench.opts.iterations);return await this.bench.opts.teardown(this,`run`),this.processRunResult({error:u,latencySamples:F}),this}runSync(){if(this.result?.error)return this;invariant(this.bench.concurrency===null,"Cannot use `concurrency` option when using `runSync`"),this.dispatchEvent(createBenchEvent(`start`,this)),invariant(!isPromiseLike(this.bench.opts.setup(this,`run`)),"`setup` function must be sync when using `runSync()`");let{error:u,samples:F}=this.benchmarkSync(`run`,this.bench.opts.time,this.bench.opts.iterations);return invariant(!isPromiseLike(this.bench.opts.teardown(this,`run`)),"`teardown` function must be sync when using `runSync()`"),this.processRunResult({error:u,latencySamples:F}),this}async warmup(){if(this.result?.error)return;this.dispatchEvent(createBenchEvent(`warmup`,this)),await this.bench.opts.setup(this,`warmup`);let{error:u}=await this.benchmark(`warmup`,this.bench.opts.warmupTime,this.bench.opts.warmupIterations);await this.bench.opts.teardown(this,`warmup`),this.postWarmup(u)}warmupSync(){if(this.result?.error)return;this.dispatchEvent(createBenchEvent(`warmup`,this)),invariant(!isPromiseLike(this.bench.opts.setup(this,`warmup`)),"`setup` function must be sync when using `runSync()`");let{error:u}=this.benchmarkSync(`warmup`,this.bench.opts.warmupTime,this.bench.opts.warmupIterations);invariant(!isPromiseLike(this.bench.opts.teardown(this,`warmup`)),"`teardown` function must be sync when using `runSync()`"),this.postWarmup(u)}async benchmark(u,F,L){if(this.fnOpts.beforeAll!=null)try{await this.fnOpts.beforeAll.call(this,u)}catch(u){return{error:u}}let R=0,z=[],B=async()=>{if(!this.isAborted())try{this.fnOpts.beforeEach!=null&&await this.fnOpts.beforeEach.call(this,u);let F;this.async?{taskTime:F}=await this.measureOnce():{taskTime:F}=this.measureOnceSync(),z.push(F),R+=F}finally{this.fnOpts.afterEach!=null&&await this.fnOpts.afterEach.call(this,u)}};try{let u;this.bench.concurrency===`task`&&(u=pLimit(Math.max(1,Math.floor(this.bench.threshold))));let V=[];for(;(R<F||z.length+(u?.activeCount??0)+(u?.pendingCount??0)<L)&&!this.isAborted();)this.bench.concurrency===`task`?V.push(u(B)):await B();!this.isAborted()&&V.length>0?await Promise.all(V):V.length>0&&Promise.allSettled(V)}catch(u){return{error:u}}if(this.fnOpts.afterAll!=null)try{await this.fnOpts.afterAll.call(this,u)}catch(u){return{error:u}}return{samples:z}}benchmarkSync(u,F,I){if(this.fnOpts.beforeAll!=null)try{invariant(!isPromiseLike(this.fnOpts.beforeAll.call(this,u)),"`beforeAll` function must be sync when using `runSync()`")}catch(u){return{error:u}}let L=0,R=[],z=()=>{if(!this.isAborted())try{this.fnOpts.beforeEach!=null&&invariant(!isPromiseLike(this.fnOpts.beforeEach.call(this,u)),"`beforeEach` function must be sync when using `runSync()`");let{taskTime:F}=this.measureOnceSync();R.push(F),L+=F}finally{this.fnOpts.afterEach!=null&&invariant(!isPromiseLike(this.fnOpts.afterEach.call(this,u)),"`afterEach` function must be sync when using `runSync()`")}};try{for(;(L<F||R.length<I)&&!this.isAborted();)z()}catch(u){return{error:u}}if(this.fnOpts.afterAll!=null)try{invariant(!isPromiseLike(this.fnOpts.afterAll.call(this,u)),"`afterAll` function must be sync when using `runSync()`")}catch(u){return{error:u}}return{samples:R}}isAborted(){return this.signal?.aborted===!0||this.bench.opts.signal?.aborted===!0}async measureOnce(){let u=this.bench.opts.now(),F=await this.fn.call(this),I=this.bench.opts.now()-u,L=getOverriddenDurationFromFnResult(F);return L!=null&&(I=L),{fnResult:F,taskTime:I}}measureOnceSync(){let u=this.bench.opts.now(),F=this.fn.call(this),I=this.bench.opts.now()-u;invariant(!isPromiseLike(F),"task function must be sync when using `runSync()`");let L=getOverriddenDurationFromFnResult(F);return L!=null&&(I=L),{fnResult:F,taskTime:I}}mergeTaskResult(u){this.result=Object.freeze({...this.result,...u})}postWarmup(u){if(u&&(this.mergeTaskResult({error:u}),this.dispatchEvent(createErrorEvent(this,u)),this.bench.dispatchEvent(createErrorEvent(this,u)),this.bench.opts.throws))throw u}processRunResult({error:u,latencySamples:F}){let I=this.isAborted();if(F&&F.length>0){this.runs=F.length;let u=F.reduce((u,F)=>u+F,0),L=getStatisticsSorted(F.sort((u,F)=>u-F)),R=getStatisticsSorted(F.map(u=>u===0?L.mean===0?0:1e3/L.mean:1e3/u).sort((u,F)=>u-F));this.mergeTaskResult({aborted:I,critical:L.critical,df:L.df,hz:R.mean,latency:L,max:L.max,mean:L.mean,min:L.min,moe:L.moe,p75:L.p75,p99:L.p99,p995:L.p995,p999:L.p999,period:u/this.runs,rme:L.rme,runtime:this.bench.runtime,runtimeVersion:this.bench.runtimeVersion,samples:L.samples,sd:L.sd,sem:L.sem,throughput:R,totalTime:u,variance:L.variance})}else I&&this.mergeTaskResult({aborted:!0});if(u&&(this.mergeTaskResult({error:u}),this.dispatchEvent(createErrorEvent(this,u)),this.bench.dispatchEvent(createErrorEvent(this,u)),this.bench.opts.throws))throw u;this.dispatchEvent(createBenchEvent(`cycle`,this)),this.bench.dispatchEvent(createBenchEvent(`cycle`,this)),this.dispatchEvent(createBenchEvent(`complete`,this))}};function getOverriddenDurationFromFnResult(u){if(typeof u==`object`&&u&&`overriddenDuration`in u&&typeof u.overriddenDuration==`number`&&Number.isFinite(u.overriddenDuration)&&u.overriddenDuration>=0)return u.overriddenDuration}var Bench=class extends EventTarget{get results(){return[...this._tasks.values()].map(u=>u.result)}get tasks(){return[...this._tasks.values()]}constructor(u={}){super(),this.concurrency=null,this.threshold=1/0,this._tasks=new Map;let{name:F,...I}=u;this.name=F,this.runtime=runtime,this.runtimeVersion=runtimeVersion,this.opts={iterations:64,now,setup:emptyFunction,teardown:emptyFunction,throws:!1,time:1e3,warmup:!0,warmupIterations:16,warmupTime:250,...I},this.opts.signal&&this.opts.signal.addEventListener(`abort`,()=>{this.dispatchEvent(createBenchEvent(`abort`))},{once:!0})}add(u,F,I={}){if(this._tasks.has(u))throw Error(`Task "${u}" already exists`);{let L=new Task(this,u,F,I);this._tasks.set(u,L),this.dispatchEvent(createBenchEvent(`add`,L))}return this}addEventListener(u,F,I){super.addEventListener(u,F,I)}getTask(u){return this._tasks.get(u)}remove(u){let F=this.getTask(u);return F&&(this.dispatchEvent(createBenchEvent(`remove`,F)),this._tasks.delete(u)),this}removeEventListener(u,F,I){super.removeEventListener(u,F,I)}reset(){this.dispatchEvent(createBenchEvent(`reset`));for(let u of this._tasks.values())u.reset()}async run(){this.opts.warmup&&await this.warmupTasks();let u=[];if(this.dispatchEvent(createBenchEvent(`start`)),this.concurrency===`bench`)u=await this.mapTasksConcurrently(u=>u.run());else for(let F of this._tasks.values())u.push(await F.run());return this.dispatchEvent(createBenchEvent(`complete`)),u}runSync(){invariant(this.concurrency===null,"Cannot use `concurrency` option when using `runSync`"),this.opts.warmup&&this.warmupTasksSync();let u=[];this.dispatchEvent(createBenchEvent(`start`));for(let F of this._tasks.values())u.push(F.runSync());return this.dispatchEvent(createBenchEvent(`complete`)),u}table(u){return this.tasks.map(F=>{if(F.result){let{error:I,latency:L,throughput:R}=F.result;return I?{"Task name":F.name,Error:I.message,Stack:I.stack}:u?.(F)??{"Task name":F.name,"Latency avg (ns)":`${formatNumber(mToNs(L.mean),5,2)} \xb1 ${L.rme.toFixed(2)}%`,"Latency med (ns)":`${formatNumber(mToNs(L.p50),5,2)} \xb1 ${formatNumber(mToNs(L.mad),5,2)}`,"Throughput avg (ops/s)":`${Math.round(R.mean).toString()} \xb1 ${R.rme.toFixed(2)}%`,"Throughput med (ops/s)":`${Math.round(R.p50).toString()} \xb1 ${Math.round(R.mad).toString()}`,Samples:L.samples.length}}return null})}async mapTasksConcurrently(u){let F=pLimit(Math.max(1,Math.floor(this.threshold))),L=[];for(let I of this._tasks.values())L.push(F(()=>u(I)));return Promise.all(L)}async warmupTasks(){if(this.dispatchEvent(createBenchEvent(`warmup`)),this.concurrency===`bench`)await this.mapTasksConcurrently(u=>u.warmup());else for(let u of this._tasks.values())await u.warmup()}warmupTasksSync(){this.dispatchEvent(createBenchEvent(`warmup`));for(let u of this._tasks.values())u.warmupSync()}};export{Bench,Task,hrtimeNow,nToMs,now}; | ||
| const tTable=[1.96,12.706204736432102,4.3026527299112765,3.182446305284264,2.7764451051977996,2.57058183661474,2.446911848791681,2.3646242510102997,2.306004135033371,2.262157162740992,2.2281388519649385,2.200985160082949,2.178812829663418,2.160368656461013,2.1447866879169277,2.131449545559323,2.1199052992210112,2.109815577833181,2.10092204024096,2.0930240544082634,2.085963447265837,2.0796138447276626,2.073873067904015,2.068657610419041,2.063898561628021,2.0595385527532946,2.0555294386428713,2.0518305164802837,2.048407141795244,2.0452296421327034,2.042272456301238,2.0395134463964077,2.0369333434601016,2.0345152974493383,2.0322445093177186,2.030107928250343,2.0280940009804507,2.0261924630291097,2.0243941645751367,2.0226909117347285,2.021075382995338,2.019540963982894,2.0180816970958815,2.0166921941428138,2.0153675699129416,2.0141033848332928,2.012895595294589,2.011740510475755,2.010634754696446,2.0095752344892093,2.0085591097152062,2.0075837681558824,2.0066468031022118,2.00574599353695,2.0048792865665233,2.0040447818101814,2.003240717496698,2.002465458054599,2.0017174830120927,2.0009953770482105,2.000297821058262,1.9996235841149783,1.9989715162223116,1.998340541772196,1.9977296536259739,1.9971379077520126,1.9965644183594748,1.996008353475506,1.9954689309194023,1.994945414632814,1.9944371113297732,1.9939433674345044,1.9934635662785831,1.9929971255321668,1.9925434948468204,1.9921021536898658,1.9916726093523491,1.9912543951146042,1.9908470685550523,1.9904502099893606,1.9900634210283845,1.9896863232444832,1.989318556936819,1.9889597799871794,1.9886096667986737,1.988267907310378,1.9879342060816723,1.9876082814405773,1.987289864690939,1.9869786993737681,1.9866745405784685,1.9863771543000652,1.9860863168388938,1.985801814239503,1.9855234417658303,1.9852510034099267,1.9849843114317696,1.9847231859278835,1.9844674544266925,1.9842169515086832,1.983971518449634,1.9837310028852815,1.9834952584959407,1.9832641447097104,1.9830375264229902,1.9828152737371547,1.9825972617102912,1.9823833701230178,1.9821734832574516,1.9819674896884745,1.9817652820865104,1.981566757031071,1.9813718148344008,1.9811803593745805,1.9809922979375068,1.9808075410672004,1.980626002423938,1.9804475986497296,1.9802722492407063,1.9800998764260065,1.979930405052777,1.9797637624769306,1.9795998784593314,1.97943868506709,1.979280116579683,1.9791241093996175,1.9789706019673938,1.978819534680521,1.9786708498163625,1.9785244914586055,1.9783804054271532,1.9782385392112587,1.9780988419057237,1.977961264150002,1.9778257580700531,1.9776922772228045,1.9775607765430836,1.977431212292894,1.9773035420129166,1.9771777244761224,1.9770537196433886,1.9769314886210223,1.97681099362009,1.9766921979174685,1.9765750658185368,1.9764595626214163,1.9763456545827007,1.9762333088845883,1.9761224936033637,1.9760131776791554,1.9759053308869141,1.9757989238085507,1.975693927806187,1.9755903149964589,1.9754880582258323,1.9753871310468787,1.9752875076954728,1.9751891630688665,1.9750920727046015,1.9749962127602256,1.9749015599937723,1.9748080917449764,1.9747157859171882,1.9746246209599583,1.9745345758522659,1.9744456300863593,1.9743577636521858,1.9742709570223849,1.974185191137821,1.9741004473936339,1.9740167076257829,1.9739339540980692,1.9738521694896138,1.9737713368827694,1.9736914397514562,1.9736124619498976,1.9735343877017435,1.9734572015895646,1.9733808885447033,1.9733054338374667,1.973230823067649,1.9731570421553692,1.9730840773322162,1.9730119151326795,1.9729405423858692,1.9728699462074992,1.9728001139921352,1.9727310334056907,1.9726626923781656,1.9725950790966158,1.9725281819983451,1.972461989764315,1.9723964913127596,1.9723316757930012,1.9722675325794565,1.972204051265833,1.9721412216594971,1.9720790337760221,1.972017477833896,1.9719565442493954,1.9718962236316093,1.9718365067776158,1.971777384667801,1.971718848461318,1.9716608894916787,1.971603499262479,1.9715466694432433,1.9714903918653972,1.9714346585183509,1.9713794615456992,1.9713247932415296,1.9712706460468354,1.9712170125460335,1.9711638854635767,1.971111257660664,1.9710591221320446,1.9710074720029072,1.97095630052586,1.9709056010779908,1.9708553671580111,1.9708055923834753,1.970756270488079,1.9707073953190282,1.9706589608344816,1.9706109611010594,1.9705633902914228,1.9705162426819125,1.9704695126502556,1.9704231946733297,1.9703772833249869,1.9703317732739336,1.9702866592816697,1.9702419362004757,1.9701975989714555,1.9701536426226303,1.9701100622670775,1.9700668531011214,1.9700240104025675,1.9699815295289818,1.969939405916016,1.9698976350757686,1.9698562125951948,1.9698151341345516,1.9697743954258797,1.9697339922715287,1.9696939205427133,1.9696541761781068,1.9696147551824699,1.9695756536253115,1.9695368676395828,1.9694983934204007,1.9694602272238055,1.9694223653655467,1.969384804219895,1.9693475402184863,1.9693105698491933,1.9692738896550193,1.9692374962330224,1.9692013862332616,1.9691655563577715,1.9691300033595551,1.9690947240416052,1.9690597152559448,1.9690249739026924,1.9689904969291443,1.968956281328883,1.9689223241409022,1.9688886224487527,1.9688551733797075,1.968821974103945,1.9687890218337525,1.968756313822743,1.968723847365097,1.9686916197948103,1.9686596284849691,1.9686278708470335,1.9685963443301415,1.968565046420423,1.9685339746403347,1.9685031265480044,1.9684724997365923,1.968442091833664,1.968411900500579,1.9683819234318907,1.9683521583547587,1.9683226030283762,1.9682932552434063,1.968264112821431,1.9682351736144144,1.9682064355041722,1.968177896401857,1.968149554247451,1.9681214070092705,1.9680934526834821,1.9680656892936232,1.968038114890141,1.9680107275499321,1.9679835253758984,1.967956506496507,1.9679296690653623,1.9679030112607847,1.9678765312853979,1.967850227365727,1.9678240977517998,1.967798140716761,1.9677723545564905,1.967746737589231,1.9677212881552217,1.967696004616341,1.967670885355754,1.9676459287775685,1.9676211333064957,1.9675964973875213,1.967572019485578,1.967547698085227,1.9675235316903468,1.9674995188238256,1.9674756580272583,1.9674519478606556,1.96742838690215,1.9674049737477135,1.9673817070108799,1.9673585853224684,1.9673356073303163,1.9673127716990173,1.9672900771096589,1.9672675222595717,1.9672451058620788,1.9672228266462515,1.9672006833566689,1.9671786747531816,1.9671567996106818,1.967135056718874,1.9671134448820529,1.9670919629188843,1.9670706096621893,1.967049383958733,1.9670282846690177,1.9670073106670771,1.9669864608402783,1.966965734089124,1.9669451293270586,1.9669246454802793,1.9669042814875488,1.9668840363000124,1.966863908881019,1.9668438982059417,1.966824003262006,1.9668042230481186,1.9667845565746986,1.9667650028635129,1.9667455609475144,1.9667262298706825,1.966707008687866,1.9666878964646288,1.9666688922770996,1.9666499952118222,1.9666312043656085,1.9666125188453965,1.9665939377681074,1.9665754602605063,1.9665570854590666,1.9665388125098342,1.966520640568296,1.9665025687992495,1.966484596376675,1.9664667224836099,1.9664489463120245,1.9664312670626998,1.9664136839451096,1.9663961961773,1.966378802985776,1.9663615036053859,1.9663442972792093,1.9663271832584475,1.9663101608023135,1.966293229177927,1.9662763876602067,1.96625963553177,1.9662429720828285,1.9662263966110878,1.9662099084216513,1.9661935068269203,1.9661771911465,1.9661609607071053,1.9661448148424667,1.9661287528932416,1.9661127742069229,1.9660968781377508,1.966081064046626,1.966065331301024,1.966049679274911,1.9660341073486605,1.9660186149089722,1.9660032013487905,1.9659878660672256,1.9659726084694753,1.9659574279667498,1.965942323976193,1.9659272959208094,1.9659123432293915,1.9658974653364458,1.9658826616821223,1.965867931712145,1.9658532748777406,1.9658386906355727,1.9658241784476738,1.965809737781378,1.9657953681092573,1.9657810689090576,1.9657668396636336,1.965752679860889,1.9657385889937122,1.9657245665599175,1.9657106120621863,1.9656967250080057,1.9656829049096134,1.9656691512839384,1.965655463652545,1.9656418415415793,1.9656282844817121,1.9656147920080864,1.9656013636602634,1.9655879989821707,1.9655746975220507,1.9655614588324102,1.965548282469968,1.9655351679956077,1.9655221149743287,1.9655091229751978,1.9654961915712998,1.9654833203396942,1.9654705088613673,1.9654577567211857,1.965445063507854,1.965432428813868,1.9654198522354724,1.9654073333726187,1.9653948718289207,1.9653824672116142,1.9653701191315152,1.9653578272029781,1.9653455910438589,1.9653334102754718,1.9653212845225516,1.9653092134132164,1.9652971965789277,1.9652852336544535,1.9652733242778317,1.9652614680903338,1.9652496647364275,1.9652379138637432,1.9652262151230366,1.9652145681681563,1.9652029726560083,1.9651914282465226,1.9651799346026202,1.9651684913901803,1.9651570982780076,1.9651457549378,1.9651344610441186,1.9651232162743548,1.9651120203087005,1.9651008728301178,1.9650897735243085,1.9650787220796855,1.9650677181873428,1.965056761541027,1.965045851837109,1.965034988774555,1.965024172054902,1.9650134013822251,1.9650026764631154,1.9649919970066518,1.9649813627243728,1.964970773330254,1.9649602285406784,1.9649497280744153,1.9649392716525922,1.964928858998672,1.9649184898384262,1.9649081638999137,1.9648978809134563,1.9648876406116125,1.9648774427291587,1.9648672870030628,1.9648571731724636,1.9648471009786466,1.9648370701650248,1.9648270804771135,1.9648171316625118,1.964807223470879,1.9647973556539153,1.9647875279653397,1.9647777401608706,1.9647679919982053,1.9647582832369994,1.9647486136388483,1.9647389829672652,1.9647293909876653,1.9647198374673442,1.9647103221754598,1.964700844883014,1.9646914053628335,1.9646820033895525,1.964672638739595,1.9646633111911553,1.9646540205241838,1.9646447665203655,1.964635548963106,1.9646263676375137,1.9646172223303833,1.9646081128301776,1.9645990389270147,1.9645900004126484,1.9645809970804544,1.9645720287254127,1.9645630951440949,1.964554196134645,1.9645453314967691,1.9645365010317148,1.9645277045422602,1.9645189418326983,1.964510212708822,1.964501516977911,1.964492854448715,1.9644842249314425,1.9644756282377454,1.9644670641807058,1.964458532574823,1.9644500332359982,1.9644415659815229,1.9644331306300662,1.9644247270016604,1.964416354917689,1.9644080142008735,1.9643997046752626,1.9643914261662165,1.9643831785003991,1.9643749615057613,1.9643667750115323,1.964358618848207,1.9643504928475335,1.964342396842502,1.9643343306673333,1.9643262941574684,1.9643182871495555,1.9643103094814403,1.964302360992155,1.9642944415219068,1.9642865509120675,1.9642786890051633,1.964270855644863,1.9642630506759702,1.9642552739444101,1.9642475252972216,1.9642398045825453,1.9642321116496164,1.9642244463487513,1.9642168085313412,1.9642091980498402,1.9642016147577568,1.964194058509645,1.9641865291610932,1.9641790265687171,1.964171550590149,1.9641641010840303,1.9641566779100006,1.9641492809286911,1.964141910001714,1.964134564991655,1.9641272457620647,1.9641199521774493,1.964112684103263,1.9641054414058998,1.9640982239526847,1.964091031611867,1.9640838642526093,1.964076721744983,1.9640696039599586,1.9640625107693983,1.9640554420460483,1.9640483976635308,1.9640413774963374,1.964034381419821,1.9640274093101877,1.9640204610444916,1.9640135365006257,1.9640066355573154,1.9639997580941106,1.963992903991381,1.9639860731303063,1.9639792653928712,1.9639724806618581,1.9639657188208401,1.9639589797541745,1.963952263346997,1.963945569485213,1.963938898055494,1.9639322489452695,1.96392562204272,1.9639190172367733,1.963912434417095,1.963905873474085,1.9638993342988706,1.9638928167832999,1.9638863208199362,1.9638798463020526,1.9638733931236256,1.9638669611793291,1.9638605503645292,1.9638541605752786,1.9638477917083106,1.963841443661033,1.9638351163315244,1.9638288096185263,1.9638225234214404,1.9638162576403206,1.96381001217587,1.9638037869294331,1.9637975818029945,1.9637913966991682,1.9637852315211985,1.9637790861729507,1.963772960558908,1.9637668545841658,1.9637607681544267,1.963754701175997,1.96374865355578,1.9637426252012729,1.9637366160205605,1.9637306259223126,1.9637246548157765,1.9637187026107747,1.9637127692177012,1.9637068545475131,1.9637009585117295,1.9636950810224274,1.9636892219922344,1.9636833813343266,1.963677558962424,1.9636717547907854,1.9636659687342057,1.96366020070801,1.9636544506280507,1.9636487184107032,1.9636430039728607,1.963637307231933,1.9636316281058388,1.9636259665130043,1.9636203223723585,1.9636146956033296,1.9636090861258415,1.9636034938603082,1.963597918727633,1.9635923606492014,1.9635868195468806,1.9635812953430134,1.9635757879604159,1.9635702973223736,1.9635648233526377,1.9635593659754214,1.9635539251153973,1.9635485006976923,1.9635430926478856,1.9635377008920054,1.9635323253565247,1.9635269659683576,1.9635216226548569,1.963516295343811,1.9635109839634397,1.9635056884423918,1.9635004087097414,1.9634951446949849,1.9634898963280374,1.9634846635392311,1.9634794462593101,1.9634742444194289,1.9634690579511493,1.9634638867864362,1.9634587308576554,1.9634535900975714,1.9634484644393435,1.9634433538165224,1.963438258163049,1.96343317741325,1.963428111501836,1.9634230603638985,1.9634180239349066,1.9634130021507055,1.9634079949475116,1.9634030022619122,1.9633980240308617,1.9633930601916791,1.963388110682045,1.9633831754399986,1.963378254403937,1.9633733475126116,1.9633684547051236,1.9633635759209254,1.9633587110998145,1.9633538601819331,1.9633490231077657,1.9633441998181338,1.9633393902541987,1.9633345943574538,1.9633298120697256,1.96332504333317,1.9633202880902698,1.9633155462838343,1.963310817856994,1.9633061027532,1.9633014009162226,1.9632967122901475,1.9632920368193745,1.963287374448614,1.9632827251228866,1.9632780887875207,1.9632734653881478,1.963268854870705,1.963264257181428,1.9632596722668525,1.9632551000738105,1.9632505405494287,1.963245993641126,1.963241459296613,1.9632369374638876,1.963232428091235,1.9632279311272245,1.963223446520709,1.9632189742208208,1.963214514176972,1.9632100663388516,1.9632056306564227,1.9632012070799227,1.9631967955598593,1.9631923960470097,1.9631880084924196,1.9631836328473993,1.9631792690635235,1.9631749170926298,1.9631705768868148,1.9631662483984351,1.9631619315801037,1.9631576263846882,1.9631533327653103,1.9631490506753435,1.963144780068411,1.963140520898385,1.9631362731193833,1.9631320366857699,1.9631278115521522,1.9631235976733785,1.9631193950045382,1.963115203500959,1.963111023118206,1.9631068538120793,1.963102695538613,1.963098548254074,1.963094411914959,1.963090286477995,1.9630861719001376,1.9630820681385661,1.963077975150687,1.963073892894129,1.9630698213267435,1.9630657604066017,1.9630617100919938,1.9630576703414275,1.9630536411136277,1.9630496223675324,1.963045614062295,1.963041616157278,1.9630376286120574,1.9630336513864166,1.9630296844403485,1.9630257277340504,1.9630217812279265,1.9630178448825841,1.963013918658834,1.9630100025176869,1.9630060964203544,1.9630022003282468,1.9629983142029712,1.9629944380063318,1.962990571700327,1.9629867152471494,1.9629828686091835,1.9629790317490055,1.962975204629381,1.9629713872132657,1.9629675794638015,1.962963781344317,1.9629599928183272,1.9629562138495296,1.9629524444018054,1.9629486844392179,1.9629449339260105,1.9629411928266058,1.962937461105606,1.9629337387277892,1.9629300256581104,1.9629263218616995,1.9629226273038602,1.9629189419500692,1.9629152657659752,1.9629115987173975,1.9629079407703247,1.9629042918909145,1.9629006520454917,1.9628970212005485,1.9628933993227415,1.9628897863788926,1.9628861823359869,1.962882587161172,1.9628790008217571,1.9628754232852115,1.9628718545191641,1.9628682944914029,1.9628647431698727,1.9628612005226753,1.9628576665180681,1.9628541411244633,1.9628506243104265,1.962847116044676,1.962843616296083,1.9628401250336684,1.9628366422266041,1.9628331678442101,1.962829701855956,1.9628262442314577,1.9628227949404782,1.9628193539529253,1.962815921238852,1.9628124967684557,1.962809080512076,1.9628056724401943,1.962802272523434,1.9627988807325591,1.9627954970384724,1.9627921214122162,1.96278875382497,1.9627853942480507,1.9627820426529121,1.9627786990111424,1.9627753632944653,1.962772035474738,1.962768715523951,1.962765403414227,1.9627620991178198,1.9627588026071152,1.9627555138546275,1.9627522328330012,1.962748959515009,1.962745693873551,1.9627424358816548,1.9627391855124732,1.9627359427392859,1.9627327075354966,1.9627294798746329,1.9627262597303463,1.9627230470764099,1.962719841886719,1.962716644135291,1.9627134537962623,1.9627102708438906,1.9627070952525512,1.9627039269967388,1.9627007660510651,1.9626976123902597,1.9626944659891674,1.9626913268227497,1.9626881948660826,1.9626850700943568,1.9626819524828756,1.9626788420070573,1.962675738642431,1.9626726423646375,1.9626695531494305,1.962666470972672,1.9626633958103352,1.9626603276385024,1.962657266433364,1.962654212171219,1.962651164828473,1.962648124381639,1.962645090807336,1.9626420640822897,1.9626390441833281,1.9626360310873863,1.9626330247715016,1.962630025212815,1.962627032388571,1.9626240462761142,1.9626210668528927,1.9626180940964544,1.9626151279844477,1.9626121684946207,1.9626092156048216,1.9626062692929966,1.9626033295371899,1.9626003963155434,1.9625974696062964,1.9625945493877848,1.9625916356384394,1.9625887283367882,1.9625858274614525,1.962582932991149,1.9625800449046875,1.9625771631809725,1.962574287799,1.9625714187378587,1.9625685559767294,1.9625656994948841,1.9625628492716856,1.9625600052865868,1.9625571675191313,1.9625543359489512,1.9625515105557676,1.9625486913193901,1.9625458782197165,1.9625430712367309,1.962540270350506,1.9625374755412,1.962534686789057,1.962531904074407,1.9625291273776646,1.96252635667933,1.9625235919599864,1.962520833200302,1.9625180803810265,1.962515333482994,1.9625125924871198,1.9625098573744026,1.9625071281259212,1.962504404722836,1.9625016871463874,1.9624989753778976,1.9624962693987664,1.9624935691904748,1.9624908747345817,1.9624881860127243,1.9624855030066184,1.9624828256980582,1.962480154068913,1.962477488101131,1.962474827776736,1.9624721730778274,1.962469523986581,1.9624668804852476,1.9624642425561525,1.962461610181696,1.9624589833443515,1.9624563620266673,1.9624537462112641,1.9624511358808356,1.9624485310181483,1.9624459316060407,1.9624433376274224,1.9624407490652758,1.9624381659026522,1.9624355881226763,1.962433015708541,1.9624304486435091,1.9624278869109137,1.9624253304941575,1.9624227793767104,1.9624202335421121,1.9624176929739703,1.9624151576559599,1.962412627571823,1.9624101027053702,1.9624075830404768,1.9624050685610865,1.962402559251207,1.9624000550949139,1.9623975560763454,1.962395062179708,1.9623925733892695,1.9623900896893647,1.9623876110643914,1.9623851374988106,1.9623826689771475,1.96238020548399,1.9623777470039887,1.962375293521857,1.9623728450223694,1.9623704014903631,1.9623679629107367,1.9623655292684494,1.9623631005485223,1.9623606767360353,1.9623582578161303,1.9623558437740083,1.9623534345949294,1.9623510302642144,1.9623486307672415,1.9623462360894495,1.962343846216334,1.962341461133449,1.9623390808264078,1.9623367052808791,1.9623343344825908,1.962331968417326,1.9623296070709262,1.9623272504292881,1.9623248984783654,1.9623225512041673,1.9623202085927578,1.9623178706302578,1.9623155373028418,1.9623132085967403,1.962310884498237,1.962308564993671,1.962306250069434,1.9623039397119733,1.9623016339077874,1.9622993326434304,1.962297035905507,1.9622947436806755,1.9622924559556474,1.962290172717185,1.9622878939521027,1.9622856196472673,1.962283349789597],emptyFunction=Object.freeze(()=>{});var BenchEvent=class extends globalThis.Event{get error(){return this.#e}get task(){return this.#t}#e;#t;constructor(i,D,O){super(i),this.#t=D,this.#e=O}};function detectRuntime(i=globalThis){let D=`unknown`,O=`unknown`;return i.Bun||i.process&&i.process.versions?.bun?(D=`bun`,O=i.Bun.version||`unknown`):i.Deno?(D=`deno`,O=i.Deno.version?.deno??`unknown`):i.process&&i.process.release?.name===`node`?(D=`node`,O=i.process.versions?.node??`unknown`):i.HermesInternal?(D=`hermes`,O=i.HermesInternal.getRuntimeProperties?.()[`OSS Release Version`]??`unknown`):hasNavigatorWithUserAgent(i)&&i.navigator.userAgent===`Cloudflare-Workers`?D=`workerd`:hasNavigatorWithUserAgent(i)&&i.navigator.userAgent.toLowerCase().startsWith(`quickjs-ng`)?(D=`quickjs-ng`,O=i.navigator.userAgent.split(`/`)[1]??`unknown`):typeof i.Netlify==`object`?D=`netlify`:typeof i.EdgeRuntime==`string`?D=`edge-light`:i.__lagon__?D=`lagon`:i.fastly?D=`fastly`:i.$262&&i.lockdown&&i.AsyncDisposableStack?D=`moddable`:i.d8?(D=`v8`,O=typeof i.version==`function`?i.version():`unknown`):i.inIon&&i.performance&&i.performance.mozMemory?D=`spidermonkey`:typeof i.$==`object`&&i.$!==null&&`IsHTMLDDA`in i.$?D=`jsc`:i.window&&i.navigator&&(D=`browser`),{runtime:D,version:O}}function hasNavigatorWithUserAgent(i=globalThis){return typeof i.navigator==`object`&&i.navigator!==null&&typeof i.navigator.userAgent==`string`}const{runtime,version:runtimeVersion}=detectRuntime(),nToMs=i=>Number(i)/1e6,mToNs=i=>Number(i)*1e6,mToMs=i=>i,nBigintToMs=i=>Number(i)/1e6,mToNsBigint=i=>BigInt(i)*1000000n,formatNumber=(i,D=5,O=2)=>{if(i===1/0)return`+∞`;if(i===-1/0)return`-∞`;if(i!==i)return`NaN`;let k=Math.abs(i);if(k>=10**D)return i.toFixed();if(k<10**(D-O))return i.toFixed(O);let A=Math.min(Math.max(0,D-(Math.floor(Math.log10(k))+1)),O);return i.toFixed(A)},isPromiseLike=i=>i!==null&&(typeof i==`object`||typeof i==`function`)&&typeof i.then==`function`,AsyncFunctionConstructor=(async()=>{}).constructor,isAsyncFunction=i=>typeof i==`function`&&i.constructor===AsyncFunctionConstructor,isFnAsyncResource=i=>{if(i==null)return!1;if(isAsyncFunction(i))return!0;try{let O=i(),k=isPromiseLike(O);if(k)try{O.then(emptyFunction).catch(emptyFunction)}catch{}return k}catch{return!1}},isValidSamples=i=>Array.isArray(i)&&i.length!==0;function sortSamples(i){i.sort(sortFn)}const meanAndVariance=i=>{let D=i.length;if(D===1)return{mean:i[0],vr:0};let O=0,k=0,A=0,j=0,M=0;for(;M<D;)A=i[M++],j=A-O,O+=j/M,k+=j*(A-O);return{mean:O,vr:k/(D-1)}},quantileSorted=(i,D)=>{let O=(i.length-1)*D,k=Math.floor(O);return k+1<i.length?i[k]+(O-k)*(i[k+1]-i[k]):i[k]},sortFn=(i,D)=>i-D,absoluteDeviationMean=(i,D)=>{let O=0,k=i.length,A=0;for(;A<k;)O+=(Math.abs(i[A++]-D)-O)/A;return O};function absoluteDeviationMedian(i,D){let O=i.length;if(O===1)return 0;let k=O>>1,A=O+1>>1,j=0,M=k,N,P,F,I,L,R;for(;j<=M;){if(N=j+M>>1,P=A-N,F=N===0?-1/0:D-i[k-N],L=N===k?1/0:D-i[k-N-1],I=P===0?-1/0:i[k+P-1]-D,R=P===O-k?1/0:i[k+P]-D,F<=R&&I<=L)return O&1?Math.max(F,I):(Math.max(F,I)+Math.min(L,R))/2;F>R?M=N-1:j=N+1}return 0}function computeStatistics(D,O=!1){let{mean:k,vr:A}=meanAndVariance(D),j=Math.sqrt(A),M=j/Math.sqrt(D.length),N=D.length-1,P=tTable[N||1]??tTable[0],F=M*P,I=k===0?1/0:F/Math.abs(k)*100,L=quantileSorted(D,.5);return{aad:absoluteDeviationMean(D,k),critical:P,df:N,mad:absoluteDeviationMedian(D,L),max:D[N],mean:k,min:D[0],moe:F,p50:L,p75:quantileSorted(D,.75),p99:quantileSorted(D,.99),p995:quantileSorted(D,.995),p999:quantileSorted(D,.999),rme:I,samples:O?D:void 0,samplesCount:D.length,sd:j,sem:M,variance:A}}const assert=(i,D)=>{if(!i){let i=Error.stackTraceLimit;try{Error.stackTraceLimit=0;let O=Error(D);throw Error.stackTraceLimit=i,i!==0&&Error.captureStackTrace(O,assert),O}finally{Error.stackTraceLimit=i}}},toError=i=>{switch(typeof i){case`function`:return Error(i.name);case`object`:if(i!==null)return i instanceof Error?i:Error(i.message??``);case`undefined`:return Error();case`string`:return Error(i);default:return Error(String(i))}},defaultConvertTaskResultForConsoleTable=i=>{let D=i.result.state;return{"Task name":i.name,...D===`aborted-with-statistics`||D===`completed`?{"Latency avg (ns)":`${formatNumber(mToNs(i.result.latency.mean))} \xb1 ${i.result.latency.rme.toFixed(2)}%`,"Latency med (ns)":`${formatNumber(mToNs(i.result.latency.p50))} \xb1 ${formatNumber(mToNs(i.result.latency.mad))}`,"Throughput avg (ops/s)":`${Math.round(i.result.throughput.mean).toString()} \xb1 ${i.result.throughput.rme.toFixed(2)}%`,"Throughput med (ops/s)":`${Math.round(i.result.throughput.p50).toString()} \xb1 ${Math.round(i.result.throughput.mad).toString()}`,Samples:i.result.latency.samplesCount}:D===`errored`?{Error:i.result.error.message,Stack:i.result.error.stack??`N/A`}:{"Latency avg (ns)":`N/A`,"Latency med (ns)":`N/A`,"Throughput avg (ops/s)":`N/A`,"Throughput med (ops/s)":`N/A`,Samples:`N/A`,Remarks:D},...D===`aborted-with-statistics`&&{Remarks:D}}},withConcurrency=async i=>{let{fn:D,iterations:O,limit:k,signal:A,time:j=0,timestampProvider:M=performanceNowTimestampProvider}=i,N=O===0?k:Math.max(0,Math.min(k,O)),P=[],F=[],I=!0,L=0,R=Number.isFinite(j)&&j>0,z=O>0,B=0,V=M.fn,H=z?R?()=>I&&L++<O&&(V()<B||(I=!1)):()=>I&&L++<O:R?()=>I&&(V()<B||(I=!1)):()=>I,U=i=>{I&&F.push(i)},W=i=>{P.push(toError(i))},G=()=>I=!1;if(A){if(A.aborted)return[];A.addEventListener(`abort`,G)}let K=async()=>{for(;H();)try{U(await D())}catch(i){I=!1,W(i);break}};R&&(B=V()+M.fromMs(j));let q=Array.from({length:N},()=>K());if(await Promise.allSettled(q),P.length===0)return F;throw P.length===1?P[0]:AggregateError(P,`Multiple errors occurred during concurrent execution`)},performanceNow=globalThis.performance.now.bind(globalThis.performance),performanceNowTimestampProvider={fn:performanceNow,fromMs:mToMs,name:`performanceNow`,toMs:mToMs},hrtimeBigint=globalThis.process?.hrtime?.bigint.bind(globalThis.process?.hrtime)??(()=>{throw Error(`hrtime.bigint() is not supported in this JS environment`)}),hrtimeNow=()=>nToMs(Number(hrtimeBigint())),hrtimeNowTimestampProvider={fn:hrtimeBigint,fromMs:mToNsBigint,name:`hrtimeNow`,toMs:nBigintToMs},bunNanoseconds=globalThis.Bun?.nanoseconds,bunNanosecondsTimestampProvider=bunNanoseconds?{fn:bunNanoseconds,fromMs:mToNs,name:`bunNanoseconds`,toMs:nToMs}:void 0;function createCustomTimestampProvider(i){return{fn:i,fromMs:mToMs,name:`custom`,toMs:mToMs}}const getTimestampProviderByJSRuntime=(i=runtime)=>i===`bun`?bunNanosecondsTimestampProvider:i===`deno`?performanceNowTimestampProvider:i===`node`?hrtimeNowTimestampProvider:performanceNowTimestampProvider,getTimestampProvider=i=>{switch(typeof i){case`function`:return createCustomTimestampProvider(i);case`string`:switch(i){case`auto`:return getTimestampProviderByJSRuntime();case`bunNanoseconds`:return bunNanosecondsTimestampProvider??performanceNowTimestampProvider;case`hrtimeNow`:return hrtimeNowTimestampProvider;default:return performanceNowTimestampProvider}case`object`:return i===null?performanceNowTimestampProvider:(assert(isValidTimestampProvider(i),`Invalid Timestamp Provider object`),i);case`undefined`:return performanceNowTimestampProvider;default:throw Error(`Invalid value for 'timestampProvider' or 'now'`)}};function isValidTimestampProvider(i){return typeof i==`object`&&!!i&&typeof i.fn==`function`&&typeof i.name==`string`&&typeof i.toMs==`function`&&typeof i.fromMs==`function`}const hookNames=[`afterAll`,`beforeAll`,`beforeEach`,`afterEach`],abortableStates=[`not-started`,`started`],notStartedTaskResult={state:`not-started`},abortedTaskResult={state:`aborted`},startedTaskResult={state:`started`};var Task=class extends EventTarget{get name(){return this.#a}get result(){return{...this.#o,runtime:this.#n.runtime,runtimeVersion:this.#n.runtimeVersion,timestampProviderName:this.#n.timestampProvider.name}}get runs(){return this.#c}#e=!1;#t;#n;#r;#i;#a;#o=notStartedTaskResult;#s;#c=0;#l;#u;#d;#f;constructor(i,D,O,k={}){super(),this.#n=i,this.#a=D,this.#r=O,this.#i=k,this.#t=k.async??isFnAsyncResource(O),this.#l=k.signal,this.#s=k.retainSamples??i.retainSamples,this.#d=i.timestampProvider,this.#u=i.timestampProvider.fn,this.#f=i.timestampProvider.toMs;for(let i of hookNames)this.#i[i]!=null&&assert(typeof this.#i[i]==`function`,`'${i}' must be a function if provided`);this.reset(!1),this.#l&&(this.#l.aborted?this.#_():this.#l.addEventListener(`abort`,this.#_.bind(this),{once:!0})),this.#n.signal&&(this.#n.signal.aborted?this.#_():this.#n.signal.addEventListener(`abort`,this.#_.bind(this),{once:!0}))}reset(i=!0){this.#c=0,this.#o=this.#e?abortedTaskResult:notStartedTaskResult,i&&this.dispatchEvent(new BenchEvent(`reset`,this))}async run(){if(this.#o.state!==`not-started`)return this;this.#o={state:`started`},this.dispatchEvent(new BenchEvent(`start`,this)),await this.#n.setup(this,`run`);let{error:i,samples:D}=await this.#p(`run`,this.#n.time,this.#n.iterations);return await this.#n.teardown(this,`run`),this.#y({error:i,latencySamples:D}),this}runSync(){if(this.#o.state!==`not-started`)return this;assert(this.#n.concurrency===null,"Cannot use `concurrency` option when using `runSync`"),this.#o=startedTaskResult,this.dispatchEvent(new BenchEvent(`start`,this)),assert(!isPromiseLike(this.#n.setup(this,`run`)),"`setup` function must be sync when using `runSync()`");let{error:i,samples:D}=this.#m(`run`,this.#n.time,this.#n.iterations);return assert(!isPromiseLike(this.#n.teardown(this,`run`)),"`teardown` function must be sync when using `runSync()`"),this.#y({error:i,latencySamples:D}),this}async warmup(){if(this.#o.state!==`not-started`)return;this.dispatchEvent(new BenchEvent(`warmup`,this)),await this.#n.setup(this,`warmup`);let{error:i}=await this.#p(`warmup`,this.#n.warmupTime,this.#n.warmupIterations);await this.#n.teardown(this,`warmup`),this.#v(i)}warmupSync(){if(this.#o.state!==`not-started`)return;this.dispatchEvent(new BenchEvent(`warmup`,this)),assert(!isPromiseLike(this.#n.setup(this,`warmup`)),"`setup` function must be sync when using `runSync()`");let{error:i}=this.#m(`warmup`,this.#n.warmupTime,this.#n.warmupIterations);assert(!isPromiseLike(this.#n.teardown(this,`warmup`)),"`teardown` function must be sync when using `runSync()`"),this.#v(i)}async#p(i,D,O){try{this.#i.beforeAll&&await this.#i.beforeAll.call(this,i);let k=0,A=[],j=async()=>{if(!this.#e)try{this.#i.beforeEach!=null&&await this.#i.beforeEach.call(this,i);let D=this.#t?await this.#h():this.#g();A.push(D),k+=D}finally{this.#i.afterEach!=null&&await this.#i.afterEach.call(this,i)}};if(this.#n.concurrency===`task`)await withConcurrency({fn:j,iterations:O,limit:Math.max(1,Math.floor(this.#n.threshold)),signal:this.#l??this.#n.signal,time:D,timestampProvider:this.#d}),this.#c=A.length;else for(;(k<D||A.length<O)&&!this.#e;)await j();return this.#i.afterAll!=null&&await this.#i.afterAll.call(this,i),isValidSamples(A)?{samples:A}:{}}catch(i){return{error:toError(i)}}}#m(i,D,O){try{this.#i.beforeAll&&assert(!isPromiseLike(this.#i.beforeAll.call(this,i)),"`beforeAll` function must be sync when using `runSync()`");let k=0,A=[],j=()=>{if(!this.#e)try{this.#i.beforeEach&&assert(!isPromiseLike(this.#i.beforeEach.call(this,i)),"`beforeEach` function must be sync when using `runSync()`");let D=this.#g();A.push(D),k+=D}finally{this.#i.afterEach&&assert(!isPromiseLike(this.#i.afterEach.call(this,i)),"`afterEach` function must be sync when using `runSync()`")}};for(;(k<D||A.length<O)&&!this.#e;)j();return this.#i.afterAll&&assert(!isPromiseLike(this.#i.afterAll.call(this,i)),"`afterAll` function must be sync when using `runSync()`"),isValidSamples(A)?{samples:A}:{}}catch(i){return{error:toError(i)}}}async#h(){let i=this.#u(),D=await this.#r.call(this),O=this.#f(this.#u()-i),k=getOverriddenDurationFromFnResult(D);return k===void 0?O:k}#g(){let i=this.#u(),D=this.#r.call(this),O=this.#f(this.#u()-i);assert(!isPromiseLike(D),"task function must be sync when using `runSync()`");let k=getOverriddenDurationFromFnResult(D);return k===void 0?O:k}#_(){if(this.#e=!0,abortableStates.includes(this.#o.state)){this.#o=abortedTaskResult;let i=new BenchEvent(`abort`,this);this.dispatchEvent(i),this.#n.dispatchEvent(i)}}#v(i){if(i){this.#o={state:`errored`,error:i};let D=new BenchEvent(`error`,this,i);if(this.dispatchEvent(D),this.#n.dispatchEvent(D),this.#n.throws)throw i}}#y({error:i,latencySamples:D}){if(isValidSamples(D)){this.#c=D.length,sortSamples(D);let i=computeStatistics(D,this.#s),O=i.mean,k=0,A=[];for(let i of D)i===0?A.push(O===0?0:1e3/O):(k+=i,A.push(1e3/i));sortSamples(A);let j=computeStatistics(A,this.#s);this.#o={state:this.#e?`aborted-with-statistics`:`completed`,latency:i,period:k/this.runs,throughput:j,totalTime:k}}else this.#e&&(this.#o=abortedTaskResult);if(i){this.#o={state:`errored`,error:i};let D=new BenchEvent(`error`,this,i);if(this.dispatchEvent(D),this.#n.dispatchEvent(D),this.#n.throws)throw i}let k=new BenchEvent(`cycle`,this);this.dispatchEvent(k),this.#n.dispatchEvent(k),this.dispatchEvent(new BenchEvent(`complete`,this))}};function getOverriddenDurationFromFnResult(i){return typeof i==`object`&&i&&`overriddenDuration`in i&&typeof i.overriddenDuration==`number`&&Number.isFinite(i.overriddenDuration)&&i.overriddenDuration>=0?i.overriddenDuration:void 0}var Bench=class extends EventTarget{concurrency;iterations;name;now;retainSamples;runtime;runtimeVersion;setup;signal;teardown;threshold;throws;time;timestampProvider;warmup;warmupIterations;warmupTime;get results(){return this.tasks.map(i=>i.result)}get tasks(){return[...this.#e.values()]}#e=new Map;constructor(i={}){super();let{name:k,...A}=i;this.name=k,this.runtime=runtime,this.runtimeVersion=runtimeVersion,this.concurrency=A.concurrency??null,this.threshold=A.threshold??1/0,this.time=A.time??1e3,this.iterations=A.iterations??64,assert(!(A.now!==void 0&&A.timestampProvider!==void 0),"Cannot set both `now` and `timestampProvider` options"),this.timestampProvider=getTimestampProvider(A.now??A.timestampProvider),this.now=()=>this.timestampProvider.toMs(this.timestampProvider.fn()),this.warmup=A.warmup??!0,this.warmupIterations=A.warmupIterations??16,this.warmupTime=A.warmupTime??250,this.setup=A.setup??emptyFunction,this.teardown=A.teardown??emptyFunction,this.throws=A.throws??!1,this.signal=A.signal,this.retainSamples=A.retainSamples===!0,this.signal&&this.signal.addEventListener(`abort`,()=>{this.dispatchEvent(new BenchEvent(`abort`))},{once:!0})}add(i,D,k={}){if(this.#e.has(i))throw Error(`Task "${i}" already exists`);{let A=new Task(this,i,D,k);this.#e.set(i,A),this.dispatchEvent(new BenchEvent(`add`,A))}return this}getTask(i){return this.#e.get(i)}remove(i){let D=this.getTask(i);return D&&(this.#e.delete(i),this.dispatchEvent(new BenchEvent(`remove`,D))),this}reset(){for(let i of this.#e.values())i.reset();this.dispatchEvent(new BenchEvent(`reset`))}async run(){this.warmup&&await this.#t(),this.dispatchEvent(new BenchEvent(`start`));let i=[];if(this.concurrency===`bench`){let D=[];for(let i of this.#e.values())D.push(i.run());i=await Promise.all(D)}else for(let D of this.#e.values())i.push(await D.run());return this.dispatchEvent(new BenchEvent(`complete`)),i}runSync(){assert(this.concurrency===null,"Cannot use `concurrency` option when using `runSync`"),this.warmup&&this.#n();let i=[];this.dispatchEvent(new BenchEvent(`start`));for(let D of this.#e.values())i.push(D.runSync());return this.dispatchEvent(new BenchEvent(`complete`)),i}table(i=defaultConvertTaskResultForConsoleTable){return this.tasks.map(i)}async#t(){if(this.dispatchEvent(new BenchEvent(`warmup`)),this.concurrency===`bench`){let i=[];for(let D of this.#e.values())i.push(D.warmup());await Promise.all(i)}else for(let i of this.#e.values())await i.warmup()}#n(){this.dispatchEvent(new BenchEvent(`warmup`));for(let i of this.#e.values())i.warmupSync()}};export{Bench,Task,formatNumber,hrtimeNow,nToMs,performanceNow as now}; |
+3
-3
| { | ||
| "name": "tinybench", | ||
| "version": "5.1.0", | ||
| "version": "6.0.0-beta.2", | ||
| "description": "🔎 A simple, tiny and lightweight benchmarking library!", | ||
| "type": "module", | ||
| "volta": { | ||
| "node": "22.21.0", | ||
| "pnpm": "10.18.3" | ||
| "node": "24.11.1", | ||
| "pnpm": "10.23.0" | ||
| }, | ||
@@ -10,0 +10,0 @@ "engines": { |
+161
-6
@@ -103,13 +103,36 @@ # Tinybench 🔎 | ||
| ## `process.hrtime` | ||
| ## Async Detection | ||
| if you want more accurate results for nodejs with `process.hrtime`, then import | ||
| the `hrtimeNow` function from the library and pass it to the `Bench` options. | ||
| Tinybench automatically detects if a task function is asynchronous by | ||
| checking if provided function is an `AsyncFunction` or if it returns a | ||
| `Promise`, by calling the provided function once. | ||
| You can also explicitly set the `async` option to `true` or `false` when adding | ||
| a task, thus avoiding the detection. This can be useful, for example, for | ||
| functions that return a `Promise` but are actually synchronous. | ||
| ```ts | ||
| import { hrtimeNow } from 'tinybench' | ||
| const bench = new Bench() | ||
| bench.add('asyncTask', async () => { | ||
| }, { async: true }) | ||
| bench.add('syncTask', () => { | ||
| }, { async: false }) | ||
| bench.add('syncTaskReturningPromiseAsAsync', () => { | ||
| return Promise.resolve() | ||
| }, { async: true }) | ||
| bench.add('syncTaskReturningPromiseAsSync', () => { | ||
| // for example running sync logic, which blocks the event loop anyway | ||
| // like fs.writeFileSync | ||
| // returns promise maybe for API compatibility | ||
| return Promise.resolve() | ||
| }, { async: false }) | ||
| await bench.run() | ||
| ``` | ||
| It may make your benchmarks slower. | ||
| ## Concurrency | ||
@@ -127,2 +150,134 @@ | ||
| ## Convert task results for `console.table()` | ||
| You can convert the benchmark results to a table format suitable for | ||
| `console.table()` using the `bench.table()` method. | ||
| ```ts | ||
| const table = bench.table() | ||
| console.table(table) | ||
| ``` | ||
| You can also customize the table output by providing a convert-function to the `table` method. | ||
| ```ts | ||
| import { Bench, type ConsoleTableConverter, formatNumber, mToNs, type Task } from 'tinybench' | ||
| /** | ||
| * The default converter function for console.table output. | ||
| * Modify it as needed to customize the table format. | ||
| */ | ||
| const defaultConverter: ConsoleTableConverter = ( | ||
| task: Task | ||
| ): Record<string, number | string> => { | ||
| const state = task.result.state | ||
| return { | ||
| 'Task name': task.name, | ||
| ...(state === 'aborted-with-statistics' || state === 'completed' | ||
| ? { | ||
| 'Latency avg (ns)': `${formatNumber(mToNs(task.result.latency.mean))} \xb1 ${task.result.latency.rme.toFixed(2)}%`, | ||
| 'Latency med (ns)': `${formatNumber(mToNs(task.result.latency.p50))} \xb1 ${formatNumber(mToNs(task.result.latency.mad))}`, | ||
| 'Throughput avg (ops/s)': `${Math.round(task.result.throughput.mean).toString()} \xb1 ${task.result.throughput.rme.toFixed(2)}%`, | ||
| 'Throughput med (ops/s)': `${Math.round(task.result.throughput.p50).toString()} \xb1 ${Math.round(task.result.throughput.mad).toString()}`, | ||
| Samples: task.result.latency.samplesCount, | ||
| } | ||
| : state !== 'errored' | ||
| ? { | ||
| 'Latency avg (ns)': 'N/A', | ||
| 'Latency med (ns)': 'N/A', | ||
| 'Throughput avg (ops/s)': 'N/A', | ||
| 'Throughput med (ops/s)': 'N/A', | ||
| Samples: 'N/A', | ||
| Remarks: state, | ||
| } | ||
| : { | ||
| Error: task.result.error.message, | ||
| Stack: task.result.error.stack ?? 'N/A', | ||
| }), | ||
| ...(state === 'aborted-with-statistics' && { | ||
| Remarks: state, | ||
| }), | ||
| } | ||
| } | ||
| const bench = new Bench({ name: 'custom table benchmark', time: 100 }) | ||
| // add tasks... | ||
| console.table(bench.table(defaultConverter)) | ||
| ``` | ||
| ## Retaining Samples | ||
| By default Tinybench does not keep the samples for `latency` and `throughput` to | ||
| minimize memory usage. Enable sample retention if you need the raw samples for | ||
| plotting, custom analysis, or exporting results. | ||
| You can enable samples retention at the bench level by setting the | ||
| `retainSamples` option to `true` when creating a `Bench` instance: | ||
| ```ts | ||
| const bench = new Bench({ retainSamples: true }) | ||
| ``` | ||
| You can also enable samples retention by setting the `retainSamples` option to | ||
| `true` when adding a task: | ||
| ```ts | ||
| bench.add('task with samples', () => { | ||
| // Task logic here | ||
| }, { retainSamples: true }) | ||
| ``` | ||
| ## Timestamp Providers | ||
| Tinybench can utilize different timestamp providers for measuring time intervals. | ||
| By default it uses `performance.now()`. | ||
| The `timestampProvider` option can be set when creating a `Bench` instance. It | ||
| accepts either a `TimestampProvider` object or shorthands for the common | ||
| providers `hrtimeNow` and `performanceNow`. | ||
| If you use `bun` runtime, you can also use `bunNanoseconds` shorthand. | ||
| You can set the `timestampProvider` to `auto` to let Tinybench choose the most | ||
| precise available timestamp provider based on the runtime. | ||
| ```ts | ||
| import { Bench } from 'tinybench' | ||
| const bench = new Bench({ | ||
| timestampProvider: 'hrtimeNow' // or 'performanceNow', 'bunNanoseconds', 'auto' | ||
| }) | ||
| ``` | ||
| If you want to provide a custom timestamp provider, you can create an object that implements | ||
| the `TimestampProvider` interface: | ||
| ```ts | ||
| import { Bench, TimestampProvider } from 'tinybench' | ||
| // Custom timestamp provider using Date.now() | ||
| const dateNowTimestampProvider: TimestampProvider = { | ||
| name: 'dateNow', // name of the provider | ||
| fn: Date.now, // function that returns the current timestamp | ||
| toMs: ts => ts, // convert the timestamp to milliseconds | ||
| fromMs: ts => ts // convert milliseconds to the format used by fn() | ||
| } | ||
| const bench = new Bench({ | ||
| timestampProvider: dateNowTimestampProvider | ||
| }) | ||
| ``` | ||
| You can also set the `now` option to a function that returns the current timestamp. | ||
| It will be converted to a `TimestampProvider` internally. | ||
| ```ts | ||
| import { Bench } from 'tinybench' | ||
| const bench = new Bench({ | ||
| now: Date.now | ||
| }) | ||
| ``` | ||
| ## Aborting Benchmarks | ||
@@ -129,0 +284,0 @@ |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
74250
13.36%786
30.35%412
60.31%3
50%