SwitchInlinevsfunction

JavaScript performance comparison

Test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    function A() {
      var a = "a" + "a";
      var b = 3 + 5;
      b += a.length;
    }
   
    function B() {
      var c = "lololtroll" + "useless" + "stuff";
      var d = Math.random();
      var e = 3e43 * d;
    }
    var cond = 2;
};
</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
inline
switch (cond) {
case 1:
  var a = "a" + "a";
  var b = 3 + 5;
  b += a.length;
  break;
case 2:
  var c = "lololtroll" + "useless" + "stuff";
  var d = Math.random();
  var e = 3e43 * d;
  break;
}
pending…
closure
switch (cond) {
case 1:
  {
    var a = "a" + "a";
    var b = 3 + 5;
    b += a.length;
  }
  break;
case 2:
  {
    var c = "lololtroll" + "useless" + "stuff";
    var d = Math.random();
    var e = 3e43 * d;
  }
  break;
}
pending…
function
switch (cond) {
case 1:
  A();
  break;
case 2:
  B();
  break;
}
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