Multiple If Then Else

JavaScript performance comparison

Test case created by SJ

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var myArr = ["one"];
};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Standard
if (myArr.length == 0) {
 
} else if (myArr.length== 1) {
    return;
} else if (myArr.length== 2) {

} else if (myArr.length== 3) {

} else if (myArr.length== 4) {

} else if (myArr.length== 5) {

} else {

}
pending…
Optimised
if (myArr.length < 3) {

  if (myArr.length == 0) {
   
  } else if (myArr.length == 1) {
    return;
  } else if (myArr.length == 2) {

  }

} else {

  if (myArr.length == 3) {

  } else if (myArr.length == 4) {

  } else if (myArr.length == 5) {

  } else {

  }

}
pending…

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

Compare results of other browsers

0 comments

Add a comment