Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Benchmark

Class for benchmarking.

Benchmark will execute by flow like this.

Each function can override with options of the constructor.

import Benchmark from 'asyncmark';


new Benchmark({
    name: 'timeout',
    fun() {
        return new Promise((resolve, reject) => {
            setTimeout(resolve, 100);
        });
    },
}).run().catch(console.error);

Hierarchy

  • Benchmark

Index

Type aliases

Static AfterEachFunc

AfterEachFunc: (count: number, msec: number) => Promise<void> | void

Type declaration

    • (count: number, msec: number): Promise<void> | void
    • Callback function for teardown each execute.

      since

      1.0.0

      Parameters

      • count: number

        Count of done tests in this benchmark.

      • msec: number

        Duration of this execution.

      Returns Promise<void> | void

      Benchmark will await if returns Promise.

Static AfterFunc

AfterFunc: (result: Result) => Promise<void> | void

Type declaration

    • (result: Result): Promise<void> | void
    • Callback function for teardown after Benchmark

      since

      1.0.0

      Parameters

      • result: Result

        Result of this benchmark.

      Returns Promise<void> | void

      Benchmark will await if returns Promise.

Static BeforeEachFunc

BeforeEachFunc: (count: number) => Promise<void> | void

Type declaration

    • (count: number): Promise<void> | void
    • Callback function for setup before each execute.

      since

      1.0.0

      Parameters

      • count: number

        Count of done tests in this benchmark.

      Returns Promise<void> | void

      Benchmark will await if returns Promise.

Static BeforeFunc

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

Type declaration

    • (): Promise<void> | void
    • Callback function for setup before execute Benchmark.

      since

      1.0.0

      Returns Promise<void> | void

      Benchmark will await if returns Promise.

Constructors

constructor

Properties

Readonly maxNumber

maxNumber: number = 10000

Maximum number of executing test. This value will be ignore if set Benchmark.number.

Readonly minNumber

minNumber: number = 30

Minimal number of executing test. This value will be ignore if set Benchmark.number.

Readonly name

name: string = "unnamed"

Name of this benchmark.

Readonly number

number: number = null

The number of executing the test. Will decide automatically in between Benchmark.minNumber to Benchmark.maxNumber if set null.

Readonly targetErrorRate

targetErrorRate: number = 0.1

Wanted maximum error rate. This value will be ignore if set Benchmark.number.

Methods

after

  • Teardown after execute benchmark.

    At the time executing this method, this is the unique object for the benchmark. So you can use this for storing testing data like a database. Data of this that set in this method will discard after call this method.

    In default, shows test result.

    Parameters

    Returns void

afterEach

  • afterEach(): any
  • Teardown after each tests.

    At the time executing this method, this is the unique object for the test. So you can use this for storing testing data. Data of this that set in this method will discard after call this method.

    In default, do nothing.

    Returns any

before

  • before(): any
  • Setup before execute benchmark.

    At the time executing this method, this is the unique object for the benchmark. So you can use this for storing testing data like a database. Data of this that set in this method will discard after call Benchmark.after

    In default, do nothing.

    Returns any

beforeEach

  • beforeEach(): any
  • Setup before each tests.

    At the time executing this method, this is the unique object for the test. So you can use this for storing testing data. Data of this that set in this method will discard after call Benchmark.afterEach

    In default, do nothing.

    Returns any

fun

  • fun(): never
  • The target function for benchmarking.

    At the time executing this method, this is the unique object for the test. So you can use this for storing testing data. Data of this that set in this method will discard after call Benchmark.afterEach

    In default, couses error that Error('target function is not defined').

    Returns never

run

  • run(context?: any, __namedParameters?: { afterTest: any; beforeTest: any }): Promise<Result>
  • Execute benchmark.

    Parameters

    • Default value context: any = {}

      The this for each benchmarking functions. __proto__ will override with this instance.

    • Default value __namedParameters: { afterTest: any; beforeTest: any } = {}

    Returns Promise<Result>

    A result of benchmark.

Generated using TypeDoc