Condition tests with only two conditions with fallback

Benchmark created on


Setup

const data = [
  'one',
  'two',
  'three'
]

let val

Test runner

Ready to run.

Testing in
TestOps/sec
If + else if + else
data.forEach((item) => {
  if (item === 'one') {
  	val = 1
  } else
  if (item === 'two') {
  	val = 2
  } else {
  	val = 0
  }
})
ready
Switch
data.forEach((item) => {
  switch (item) {
  	case 'one':
  	  val = 1
  	  break
  	case 'two':
  	  val = 2
  	default:
  	  val = 0
  }
})
ready

Revisions

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