inner function vs static

JavaScript performance comparison

Revision 5 of this test case created by Matt Savage

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    function passTheFunc(func) {
      var p = 1;
      var x = p / 1000;
    }
};
</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
inner function
function setupAlert() {
  passTheFunc(function() {
    var msg = 'hi';
  }, 100);
}
function setupAlert2() {
  passTheFunc(function() {
    var msg = 'rose';
  }, 100);
}
function setupAlert3() {
  passTheFunc(function() {
    var msg = 'rose';
  }, 100);
}
function setupAlert4() {
  passTheFunc(function() {
    var msg = 'rose';
  }, 100);
}
function setupAlert5() {
  passTheFunc(function() {
    var msg = 'rose';
  }, 100);
}

setupAlert();
setupAlert2();
setupAlert3();
setupAlert4();
setupAlert5();
pending…
static
function reuse() {
  var msg = 'hi';
}

function setupAlert() {
  passTheFunc(reuse, 100);
}
function setupAlert2() {
  passTheFunc(reuse, 100);
}
function setupAlert3() {
  passTheFunc(reuse, 100);
}
function setupAlert4() {
  passTheFunc(reuse, 100);
}
function setupAlert5() {
  passTheFunc(reuse, 100);
}

setupAlert();
setupAlert2();
setupAlert3();
setupAlert4();
setupAlert5();
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. Here’s a list of current revisions for this page:

0 comments

Add a comment