Case vs string creation (v3)

Revision 3 of this benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
String creation
const counts = {
	oneThing: 0,
	twoThing: 0,
	threeThing: 0
};

const incrementThing = (numberStr) => {
	counts[`${numberStr}Thing`]++;
}

for (let i = 0; i < 1000000; ++i) {
	incrementThing('one');
	incrementThing('two');
	incrementThing('three');
}
ready
Case statement
const counts = {
	oneThing: 0,
	twoThing: 0,
	threeThing: 0
};

const incrementThing = (numberStr) => {
	switch(numberStr) {
		case 'one':
		    counts['oneThing']++;
		    break;
		case 'two':
		    counts['twoThing']++;
		    break;
	    case 'three':
		    counts['threeThing']++;
		    break;
	}
}

for (let i = 0; i < 1000000; ++i) {
	incrementThing('one');
	incrementThing('two');
	incrementThing('three');
}
ready

Revisions

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