Options
All
  • Public
  • Public/Protected
  • All
Menu

@thi.ng/bench

Index

Type aliases

OptsWithoutTitle

OptsWithoutTitle: Omit<BenchmarkOpts, "title">

TimingResult

TimingResult<T>: [T, number]

Type parameters

  • T

Variables

Const DEFAULT_OPTS

DEFAULT_OPTS: BenchmarkOpts = ...

Const FORMAT_CSV

FORMAT_CSV: BenchmarkFormatter = ...

Const FORMAT_DEFAULT

FORMAT_DEFAULT: BenchmarkFormatter = ...

Const FORMAT_MD

FORMAT_MD: BenchmarkFormatter = ...

Functions

Const EMPTY

  • EMPTY(): string

Const FLOAT

  • FLOAT(x: number): string
  • Parameters

    • x: number

    Returns string

Const bench

  • bench<T>(fn: () => T, n?: number, prefix?: string): T
  • Executes given function n times, prints elapsed time to console and returns last result from fn. The optional prefix will be displayed with the output, allowing to label different measurements.

    Type parameters

    • T

    Parameters

    • fn: () => T

      function to time

        • (): T
        • Returns T

    • n: number = 1e6

      number of iterations

    • prefix: string = ""

    Returns T

Const benchResult

  • Similar to bench, but produces no output and instead returns tuple of fn's last result and the grand total time measurement.

    Type parameters

    • T

    Parameters

    • fn: () => T

      function to time

        • (): T
        • Returns T

    • n: number = 1e6

      number of iterations

    Returns TimingResult<T>

Const benchmark

Const now

  • now(): number | bigint
  • If available, returns wrapper for process.hrtime.bigint() else falls back to Date.now(). In all cases, returns a nanosec-scale timestamp, either as bigint or number.

    Returns number | bigint

Const outputString

  • outputString(str: string): false | void
  • Only outputs non-empty strings to console.

    internal

    Parameters

    • str: string

    Returns false | void

Const suite

Const timed

  • timed<T>(fn: () => T, prefix?: string): T
  • Calls function fn without args, prints elapsed time and returns fn's result. The optional prefix will be displayed with the output, allowing to label different measurements.

    Type parameters

    • T

    Parameters

    • fn: () => T

      function to time

        • (): T
        • Returns T

    • prefix: string = ""

      log prefix

    Returns T

Const timedResult

  • Similar to timed, but produces no output and instead returns tuple of fn's result and the time measurement (in milliseconds).

    Type parameters

    • T

    Parameters

    • fn: () => T

      function to time

        • (): T
        • Returns T

    Returns TimingResult<T>

Generated using TypeDoc