Skip to main content

Class: Variation

Extends​

  • BenchmarkBase

Constructors​

new Variation()​

new Variation(name): Variation

Parameters​

• name: string

Returns​

Variation

Overrides​

BenchmarkBase.constructor

Defined in​

src/variation.ts:10

Properties​

action?​

optional action: Action

Inherited from​

BenchmarkBase.action

Defined in​

src/shared-api.ts:13


cliArgs​

cliArgs: string[] = []

Defined in​

src/variation.ts:7


environment​

environment: Partial<ProcessEnv> = {}

Defined in​

src/variation.ts:6


errorStrategy?​

optional errorStrategy: ErrorStrategy

Inherited from​

BenchmarkBase.errorStrategy

Defined in​

src/shared-api.ts:14


name​

name: string

Defined in​

src/variation.ts:10


setupEachMethods​

setupEachMethods: SetupMethod[] = []

Inherited from​

BenchmarkBase.setupEachMethods

Defined in​

src/shared-api.ts:9


setupMethods​

setupMethods: SetupMethod[] = []

Inherited from​

BenchmarkBase.setupMethods

Defined in​

src/shared-api.ts:10


teardownEachMethods​

teardownEachMethods: TeardownMethod[] = []

Inherited from​

BenchmarkBase.teardownEachMethods

Defined in​

src/shared-api.ts:12


teardownMethods​

teardownMethods: TeardownMethod[] = []

Inherited from​

BenchmarkBase.teardownMethods

Defined in​

src/shared-api.ts:11

Methods​

get()​

get<T>(key): undefined | T

Gets a value from the variation's context. Returns undefined if the key is not found.

Type Parameters​

• T

Parameters​

• key: string

Returns​

undefined | T

Example​

b.withAction((variation) => {
const driver = variation.get<Driver>('driver');
driver.connect();
});

Defined in​

src/variation.ts:45


getOrDefault()​

getOrDefault<T>(key, defaultValue): T

Gets a value from the variation's context with a default value. Returns the default if the key is not found.

Type Parameters​

• T

Parameters​

• key: string

• defaultValue: T

Returns​

T

Example​

const iterations = variation.getOrDefault<number>('iterations', 10);

Defined in​

src/variation.ts:58


withAction()​

withAction(action): this

Parameters​

• action: Action

Returns​

this

Inherited from​

BenchmarkBase.withAction

Defined in​

src/shared-api.ts:36


withCliArgs()​

withCliArgs(...args): this

Parameters​

• ...args: string[]

Returns​

this

Defined in​

src/variation.ts:160


withContext()​

withContext<T>(key, value): this

Sets a value in the variation's context. This allows passing custom data to the action without using environment variables.

Type Parameters​

• T

Parameters​

• key: string

• value: T

Returns​

this

Example​

new Variation('fast-impl')
.withContext('implementation', fastProcessor)
.withAction((variation) => {
const impl = variation.get<DataProcessor>('implementation');
impl.process(data);
})

Defined in​

src/variation.ts:28


withEnvironmentVariable()​

withEnvironmentVariable(name, value): this

Parameters​

• name: string

• value: string

Returns​

this

Defined in​

src/variation.ts:155


withEnvironmentVariables()​

withEnvironmentVariables(env): this

Parameters​

• env: Partial<ProcessEnv>

Returns​

this

Defined in​

src/variation.ts:147


withErrorStrategy()​

withErrorStrategy(errorStrategy): this

Parameters​

• errorStrategy: ErrorStrategy

Returns​

this

Inherited from​

BenchmarkBase.withErrorStrategy

Defined in​

src/shared-api.ts:41


withSetup()​

withSetup(setup): this

Parameters​

• setup: SetupMethod

Returns​

this

Inherited from​

BenchmarkBase.withSetup

Defined in​

src/shared-api.ts:16


withSetupEach()​

withSetupEach(setup): this

Parameters​

• setup: SetupMethod

Returns​

this

Inherited from​

BenchmarkBase.withSetupEach

Defined in​

src/shared-api.ts:21


withTeardown()​

withTeardown(teardown): this

Parameters​

• teardown: TeardownMethod

Returns​

this

Inherited from​

BenchmarkBase.withTeardown

Defined in​

src/shared-api.ts:26


withTeardownEach()​

withTeardownEach(teardown): this

Parameters​

• teardown: TeardownMethod

Returns​

this

Inherited from​

BenchmarkBase.withTeardownEach

Defined in​

src/shared-api.ts:31


FromCliArgs()​

static FromCliArgs(args): Variation[]

Parameters​

• args: (string | string[])[]

An array of options to pass to the CLI. If an element is an array, they will be treated as alternatives.

Returns​

Variation[]

An array of variations. Can be applied with withVariations.

Example​

// Creates 2 variations, both with --flag, but one with --no-daemon and the other with --daemon.
const variations = Variation.FromCliArgs([
'--flag',
['--no-daemon', '--daemon'],
]);

// Creates 4 variations, with combinations of --a and --b.
const variations = Variation.FromCliArgs([
['--a', '--b'],
]);

Defined in​

src/variation.ts:103


FromContexts()​

static FromContexts<T>(key, values): Variation[]

Creates variations with context values for a single key. Useful for swapping implementations or configurations.

Type Parameters​

• T

Parameters​

• key: string

The context key to set

• values: readonly readonly [string, T][]

Array of [name, value] tuples

Returns​

Variation[]

An array of variations with context set

Example​

const variations = Variation.FromContext('processor', [
['loop', loopProcessor],
['reduce', reduceProcessor],
]);

benchmark.withVariations(variations);
benchmark.withAction((variation) => {
const processor = variation.get<DataProcessor>('processor');
processor.process(data);
});

Defined in​

src/variation.ts:138


FromEnvironmentVariables()​

static FromEnvironmentVariables(variables): Variation[]

Parameters​

• variables: EnvironmentVariableOptions

Returns​

Variation[]

Defined in​

src/variation.ts:62