Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Suite

A set of Benchmarks for executing those sequential or parallel.

Suite will execute by flow like this.

Each function can override with options of the constructor.

Example

import {Suite} from 'asyncmark';


const suite = new Suite({
    name: 'ways to find a character',
    beforeEach() {
        this.text = 'hello world';
    },
    parallel: true,
});

suite.add(function() {
    /o/.test(this.text);
});

suite.add({
    name: 'String#indexOf',
    before() {
        console.log('starting String#indexOf...');
    },
    fun() {
        this.text.indexOf('o') > -1;
    },
});

suite.add(new Benchmark({
    name: 'String#match',
    fun() {
        Boolean(this.text.match(/o/));
    },
    after(result) {
        console.log('String#match is done! ' + result);
    },
}));

suite.run()
    .then(results => {
        let min = results[0];
        results.forEach(x => {
            if (min.average > x.average) {
                min = x;
            }
        });
        console.log(min.name + ' is best way!');
    }).
    catch(err => console.error(err));

Hierarchy

  • Suite

Index

Type aliases

Static AfterEachFunc

AfterEachFunc: (count: number, benchmark: Benchmark, result: Result) => Promise<void> | void

Type declaration

    • (count: number, benchmark: Benchmark, result: Result): Promise<void> | void
    • Callback function for setup before each child Benchmark or Suite.

      since

      1.0.0

      Parameters

      • count: number

        Count of done benchmarks in this suite.

      • benchmark: Benchmark

        A Benchmark instance that executed.

      • result: Result

        A result of this benchmark.

      Returns Promise<void> | void

      Some Promise for awaiting, or undefined.

Static AfterFunc

AfterFunc: (results: Result[]) => Promise<void> | void

Type declaration

    • (results: Result[]): Promise<void> | void
    • Callback function for teardown before execute Suite or Benchmark.

      since

      1.0.0

      Parameters

      • results: Result[]

        a list of benchmark result.

      Returns Promise<void> | void

      Some Promise for awaiting, or undefined.

Static AfterTestFunc

AfterTestFunc: (suiteCount: number, benchCount: number, benchmark: Benchmark, msec: number) => Promise<void> | void

Type declaration

    • (suiteCount: number, benchCount: number, benchmark: Benchmark, msec: number): Promise<void> | void
    • Callback function for teardown after each execution target function.

      since

      1.0.0

      Parameters

      • suiteCount: number

        Count of done benchmarks in this suite.

      • benchCount: number

        Count of done tests in this benchmark.

      • benchmark: Benchmark

        A Benchmark instance that executed.

      • msec: number

        A result of this test.

      Returns Promise<void> | void

      Some Promise for awaiting, or undefined.

Static BeforeEachFunc

BeforeEachFunc: (count: number, benchmark: Benchmark | Suite) => Promise<void> | void

Type declaration

    • Callback function for setup before each child Benchmark or Suite.

      since

      1.0.0

      Parameters

      • count: number

        Count of done benchmarks in this suite.

      • benchmark: Benchmark | Suite

        A Benchmark instance that will execute.

      Returns Promise<void> | void

      Some Promise for awaiting, or undefined.

Static BeforeFunc

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

Type declaration

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

      since

      1.0.0

      Returns Promise<void> | void

      Some Promise for awaiting, or undefined.

Static BeforeTestFunc

BeforeTestFunc: (suiteCount: number, benchCount: number, benchmark: Benchmark) => Promise<void> | void

Type declaration

    • (suiteCount: number, benchCount: number, benchmark: Benchmark): Promise<void> | void
    • Callback function for setup before each execution target function.

      since

      1.0.0

      Parameters

      • suiteCount: number

        Count of done suite or benchmarks in this suite.

      • benchCount: number

        Count of done execution in this benchmark.

      • benchmark: Benchmark

        A Benchmark instance that will execute.

      Returns Promise<void> | void

      Some Promise for awaiting, or undefined.

Constructors

constructor

Properties

benchmarkDefault

benchmarkDefault: BenchmarkOptions

Default options for benchmarks in this suite.

benchmarks

benchmarks: (Benchmark | Suite)[] = []

A list of Benchmark or Suite.

Readonly name

name: string = "unnamed"

Name of this suite.

parallel

parallel: boolean = false

Flag for executing each benchmark parallelly.

Methods

add

addBenchmark

addSuite

  • Adding child Suite instance into this Suite.

    Parameters

    • suite: Suite

      The suite instance for adding.

    Returns Suite

    Returns this suite for method chain.

after

  • after(): any
  • Teardown after execute all benchmarks.

    At the time executing this method, this is the unique object for the suite. 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, do nothing.

    Returns any

afterEach

  • afterEach(): any
  • Teardown after execute each 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, do nothing.

    Returns any

afterTest

  • afterTest(): any
  • Teardown after execute each test of benchmarks.

    At the time executing this method, this is the unique object for the test. 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, do nothing.

    Returns any

before

  • before(): any
  • Setup before execute all benchmarks.

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

    In default, do nothing.

    Returns any

beforeEach

  • beforeEach(): any
  • Setup before execute each child Benchmark or Suite.

    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 Suite.afterEach.

    In default, do nothing.

    Returns any

beforeTest

  • beforeTest(): any
  • Setup before execute each test of benchmarks.

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

    In default, do nothing.

    Returns any

run

  • Execute benchmarks in this suite.

    All benchmarks will execute parallel if enabled Suite.parallel option. Else do execute sequentially by added order.

    Parameters

    • Default value context: any = {}

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

    • Default value callbacks: TestCallbacks = {}

      Callback functions.

    Returns Promise<Result[]>

    An array of Results.

Generated using TypeDoc