switch vs if

Benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
switch
 switch (true) {
        case null:
          return false
        case 1:
          return true
        case 2:
          return true
        case 3:
          return true
        case 4:
          return true
        case 5:
          return true
        default:
          return true
      }
ready
if
if( true == null ) {
	return true
} else if( true == 1 ) {
	return true
} else if( true == 2 ) {
	return true
} else if( true == 3 ) {
	return true
} else if( true == 4 ) {
	return true
} else if( true == 5 ) {
	return true
} else {
	return true
}
ready

Revisions

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