Conditionals

Benchmark created on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js"></script>
<script>
 var a = 1234,
     x; /* From http://snipplr.com/view/12299/is-value-in-array/ */
 
 function isValueInArray(arr, val) {
  inArray = false;
  for (i = 0; i < arr.length; i++) {
   if (val === arr[i]) {
    inArray = true;
   }
  }
  return inArray;
 }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Or
x = ((a === 1) || (a === 2) || (a === 3) || (a === 1234));
ready
isValueInArray
x = isValueInArray([1, 2, 3, 1234], a);
ready
Regex
//http://snook.ca/archives/javascript/testing_for_a_v#c24260
x = /^(?:1|2|3|1234)$/.test(a)
ready
.any
//http://snook.ca/archives/javascript/testing_for_a_v#c28145
x = [1, 2, 3, 1234].any(a)
ready
switch
switch a {
 1234: x = true;
 break;
default:
 x = false;
}
ready

Revisions

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