stateStack (stateless vs statefull)

JavaScript performance comparison

Test case created by Alexei Zaviruha

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  function statesStack1(schema, statePath) {
  	return statePath.split('.').reduce(([processed, current], token) => {
  		const state = current[token];
  
  		return [processed.concat([state]), state.child];
  	}, [[], schema])[0];
  }
  
  function statesStack2(schema, statePath) {
  	const tokens = statePath.split('.');
  	const result = [];
  	let currentSchema = schema;
  
  	for (let i = 0; i < tokens.length; i++) {
  		const token = tokens[i];
  		const state = currentSchema[token];
  
  		result.push(state);
  		currentSchema = state.child;
  	}
  
  	return result;
  }
  
  var schema = {
  	state1: {
  		inputs: {
  			'state2-requested': {
  				targetStateId: 'state2.subState1',
  				actionId: 'action1',
  			},
  
  			'some-input': { value: 42 },
  		},
  
  		child: {
  			subState1: {},
  
  			subState2: {
  				inputs: {
  					'some-input': { value: 43 },
  				}
  			},
  		},
  	},
  
  	state2: {
  		inputs: {
  			'state1-requested': {
  				state: 'state1',
  				action: 'action2',
  			},
  		},
  
  		child: {
  			subState1: {
  				child: {
  					subSubState1: {},
  					subSubState2: {},
  				},
  			},
  			subState2: {},
  		},
  	},
  };
  

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
stateless (reduce)
statesStack1(schema, 'state1.subState1');
pending…
statefull (for and mutable var)
statesStack2(schema, 'state1.subState1');
pending…

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

0 Comments