switch vs bastardized python switch

Benchmark created on


Setup

const availability = 2;

Test runner

Ready to run.

Testing in
TestOps/sec
switch
let level;
switch ( availability ) {
	case 1:
		level = "INCOMPATIBLE";
		break;
	case 2:
		level = "RISK";
		break;
	case 3:
		level = "COMPATIBLE";
		break;
	default:
		level = null;
}
ready
dictionary thing
const level = {
  	[1]: "INCOMPATIBLE",
  	[2]: "RISK",
  	[3]: "COMPATIBLE"
}[availability] ?? null;
ready

Revisions

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