Nested Functions Looped

JavaScript performance comparison

Revision 3 of this test case created by Thorsten Lorenz

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var calls = 10000;
  
  function notNested() {
    function foo() {
      return 0;
    }
  
    function bar() {
      foo();
    }
  
    for (var i = 0; i < calls; i++) {
      bar();
    }
  }
  
  function nested() {
    function bar() {
      function foo() {
        return 0;
      }
      foo();
    }
  
    for (var i = 0; i < calls; i++) {
      bar();
    }
  }
  
  function nestedReturning() {
    var bar = (function() {
      function foo() {
        return 0;
      }
  
      return function() {
        foo();
      };
  
    })();
  
    for (var i = 0; i < calls; i++) {
      bar();
    }
  }

};
</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
Unnested
notNested();
pending…
Nested
nested();
pending…
Nested Returning
nestedReturning();
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