performance testing of named or anonymous functions

JavaScript performance comparison

Revision 44 of this test case created by John

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var power = 10;
  
  var expressionFunction = function(base) {
    return Math.pow(base, power);
  };
  
  function declaredFunction(base) {
    return Math.pow(base, power);
  }

};
</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
anonymous
for (var i = 0; i < 10000; ++i) {
  var myEventHandler = function(base) {
    return Math.pow(base, 10);
  };

  var x = myEventHandler(i);
}
pending…
function expression
for (var i = 0; i < 10000; ++i) {
  var x = expressionFunction(i);
}
pending…
function declaration


for (var i = 0; i < 10000; ++i) {
  var x = declaredFunction(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