Switch case string comparison vs ref comparison

Benchmark created on


Setup

const TYPE_THING = {name: "RECORD"}
const TYPE_THING2={name: "SHOW"}
const obj1 = TYPE_THING

Test runner

Ready to run.

Testing in
TestOps/sec
switch using string
switch(obj1.name){
	case TYPE_THING2.name:
		return false;
	case TYPE_THING.name:
		return true;
	default:
		return false;
}
ready
switch using obj ref
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.