Class: Variation
Extends
BenchmarkBase
Constructors
new Variation()
new Variation(
name):Variation
Parameters
• name: string
Returns
Overrides
BenchmarkBase.constructor
Defined in
Properties
action?
optionalaction:Action
Inherited from
BenchmarkBase.action
Defined in
cliArgs
cliArgs:
string[] =[]
Defined in
environment
environment:
Partial<ProcessEnv> ={}
Defined in
errorStrategy?
optionalerrorStrategy:ErrorStrategy
Inherited from
BenchmarkBase.errorStrategy
Defined in
name
name:
string
Defined in
setupEachMethods
setupEachMethods:
SetupMethod[] =[]
Inherited from
BenchmarkBase.setupEachMethods
Defined in
setupMethods
setupMethods:
SetupMethod[] =[]
Inherited from
BenchmarkBase.setupMethods
Defined in
teardownEachMethods
teardownEachMethods:
TeardownMethod[] =[]
Inherited from
BenchmarkBase.teardownEachMethods
Defined in
teardownMethods
teardownMethods:
TeardownMethod[] =[]
Inherited from
BenchmarkBase.teardownMethods
Defined in
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
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
withAction()
withAction(
action):this
Parameters
• action: Action
Returns
this
Inherited from
BenchmarkBase.withAction
Defined in
withCliArgs()
withCliArgs(...
args):this
Parameters
• ...args: string[]
Returns
this
Defined in
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
withEnvironmentVariable()
withEnvironmentVariable(
name,value):this
Parameters
• name: string
• value: string
Returns
this
Defined in
withEnvironmentVariables()
withEnvironmentVariables(
env):this
Parameters
• env: Partial<ProcessEnv>
Returns
this
Defined in
withErrorStrategy()
withErrorStrategy(
errorStrategy):this
Parameters
• errorStrategy: ErrorStrategy
Returns
this
Inherited from
BenchmarkBase.withErrorStrategy
Defined in
withSetup()
withSetup(
setup):this
Parameters
• setup: SetupMethod
Returns
this
Inherited from
BenchmarkBase.withSetup
Defined in
withSetupEach()
withSetupEach(
setup):this
Parameters
• setup: SetupMethod
Returns
this
Inherited from
BenchmarkBase.withSetupEach
Defined in
withTeardown()
withTeardown(
teardown):this
Parameters
• teardown: TeardownMethod
Returns
this
Inherited from
BenchmarkBase.withTeardown
Defined in
withTeardownEach()
withTeardownEach(
teardown):this
Parameters
• teardown: TeardownMethod
Returns
this
Inherited from
BenchmarkBase.withTeardownEach
Defined in
FromCliArgs()
staticFromCliArgs(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
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
FromContexts()
staticFromContexts<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
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
FromEnvironmentVariables()
staticFromEnvironmentVariables(variables):Variation[]
Parameters
• variables: EnvironmentVariableOptions