Switch case string comparison vs ref comparison (v2)

Revision 2 of this benchmark created on


Setup

const TYPE_THING = {name: "RECORD"}
const TYPE_THING2={name: "SHOW"}
const obj1 = TYPE_THING
const TEST_CASES = new Array(10000).fill(1)

Test runner

Ready to run.

Testing in
TestOps/sec
switch using string
const test = TEST_CASES.map(()=>{switch(obj1.name){
	case TYPE_THING2.name:
		return false;
	case TYPE_THING.name:
		return true;
	default:
		return false;
}})
ready
switch using obj ref
const test = TEST_CASES.map(()=>{switch(obj1){
	case TYPE_THING2:
		return false;
	case TYPE_THING:
		return true;
	default:
		return false;
}})
ready

Revisions

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