Condition tests with only two conditions

Benchmark created on


Setup

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

let val

Test runner

Ready to run.

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

Revisions

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