else if case

JavaScript performance comparison

Revision 3 of this test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var mySwitch = {
      'a': function () {
        console.log('a',i);
      },
      'b': function () {
        console.log('b',i);
      },
      'c': function () {
        console.log('c', i);
      },
      'd': function () {
        console.log('d',i);
      },
      'default': function () {
        console.log('default', i);
      }
    };

};
</script>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
else if
var i = 'a';
if (i == 'a') {
  console.log('a',i);
} else if (i == 'b') {
  console.log('b',i);
} else if (i == 'c') {
  console.log('c',i);
} else if (i == 'd') {
  console.log('d',i);
}
pending…
case
var i = 'a';
switch (i) {
case "a":
  console.log('a',i);
  break;
case "b":
  console.log('b',i);
  break;
case "c":
  console.log('c',i);
  break;
case "d":
  console.log('d',i);
  break;
default:
  console.log('default',i);
  break;
}
pending…
object
var i = 'a';

if (!mySwitch[i]) {
  i = 'default';
}

mySwitch[i]();

pending…

Compare results of other browsers

Revisions

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

0 Comments