Actions

Benchmark created on


Setup

class ActionType {
	inputs = [];
	constructor(name){
		this.name = name;
	}
	addInput(input){
		this.inputs.push(input);
	}
}

function creator(type) {
  function Action(value) {
    return {
      creator: Action,
      value,
    };
  }
  Action.type = new ActionType(type);
  return Action;
}

class Predefined {
	constructor(type, inputs, value, actionCreator){
		this.type = type;
		this.inputs = inputs;
		this.value = value;
		this.actionCreator = actionCreator;
	}
	addInput(input){
		this.inputs.push(input);
	}
}

function predefined(type){
	const inputs = [];
	function ActionCreator(value){
		return new Predefined(type, inputs, value,ActionCreator);
	}
	ActionCreator.inputs = inputs;
	return ActionCreator;
}

function predefined2(type){
	const inputs = [];
	return function ActionCreator(value){
		return new Predefined(type, inputs, value, ActionCreator);
	}
}

let result;
const iter = 1;

Test runner

Ready to run.

Testing in
TestOps/sec
fn
const Action = creator('test');
const action = Action(10);
Action.type.inputs.length = 0;
for(let i=0;i<iter;i++){
    Action.type.addInput('input');
}
result = action;
ready
predefined
const Action = predefined('test');
const action = Action(10);
action.inputs.length = 0;
for(let i=0;i<iter;i++){
    Action.inputs.push('input');
}
result = action;
ready
predefined (action)
const Action = predefined('test');
const action = Action(10);
action.inputs.length = 0;
for(let i=0;i<iter;i++){
    action.addInput('input');
}
result = action;
ready
predefined2
const Action = predefined2('test');
const action = Action(10);
action.inputs.length = 0;
for(let i=0;i<iter;i++){
    action.addInput('input');
}
result = action;
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.