Options
All
  • Public
  • Public/Protected
  • All
Menu

asyncmark

Index

Type aliases

BenchmarkOptions

BenchmarkOptions: { after?: AfterFunc; afterEach?: AfterEachFunc; before?: BeforeFunc; beforeEach?: BeforeEachFunc; fun?: TargetFunc; maxNumber?: number; minNumber?: number; name?: string; number?: number; targetErrorRate?: number }

The options for Benchmark.

since

0.3.4

Type declaration

Operator

Operator: "<" | "<=" | ">" | ">="

Assertion operator type.

SuiteOptions

SuiteOptions: { after?: AfterFunc; afterEach?: AfterEachFunc; afterTest?: AfterTestFunc; before?: BeforeFunc; beforeEach?: BeforeEachFunc; beforeTest?: BeforeTestFunc; benchmarkDefault?: BenchmarkOptions; name?: string; parallel?: boolean }

The options for Suite.

since

0.3.4

Type declaration

TargetFunc

TargetFunc: () => Promise<void> | void

Type declaration

    • (): Promise<void> | void
    • The target function for benchmarking.

      since

      1.0.0

      Returns Promise<void> | void

      If returns Promise, Benchmark will measure the time it takes for the Promise to resolve. Otherwise will measure the time it to method return.

TestCallbacks

TestCallbacks: { afterTest?: (count: number, benchmark: Benchmark, msec: number) => Promise<void> | void; beforeTest?: (count: number, benchmark: Benchmark) => Promise<void> | void }

Callback functions set.

since

0.3.4

Type declaration

  • Optional afterTest?: (count: number, benchmark: Benchmark, msec: number) => Promise<void> | void
      • (count: number, benchmark: Benchmark, msec: number): Promise<void> | void
      • Callback function that will be called when after executing each test.

        Parameters

        • count: number

          Count of done tests in this benchmark.

        • benchmark: Benchmark

          This Benchmark.

        • msec: number

          Duration of this execution.

        Returns Promise<void> | void

        Promise for awaiting, or undefined.

  • Optional beforeTest?: (count: number, benchmark: Benchmark) => Promise<void> | void
      • (count: number, benchmark: Benchmark): Promise<void> | void
      • Callback function that will be called when before executing each test.

        Parameters

        • count: number

          Count of done tests in this benchmark.

        • benchmark: Benchmark

          This Benchmark.

        Returns Promise<void> | void

        Promise for awaiting, or undefined.

Functions

timeit

  • timeit<T, U>(fun: (...args: T) => Promise<void> | void, args?: T, context?: U): Promise<number>
  • Measure tiem to execute a function.

    wait for done if the target function returns a thenable object. so you can use async function.

    NOTE: this function will execute target function only once.

    since

    0.2.4

    Type parameters

    • T: unknown[]

    • U: Record<string, unknown>

    Parameters

    • fun: (...args: T) => Promise<void> | void

      The target function.

        • (...args: T): Promise<void> | void
        • Parameters

          • Rest ...args: T

          Returns Promise<void> | void

    • Default value args: T = [] as unknown as T

      Arguments to passing to target function.

    • Default value context: U = {} as U

      The this for target function.

    Returns Promise<number>

    milliseconds taked executing.

    Examples

    Simple usage

    const msec = await timeit(function() {
        # do something heavy.
    });

    With arguments

    console.log(await timeit(axios.get, ['http://example.com']));

    Changelog

    • 1.0.0: Changed arguments order.

Generated using TypeDoc