Nested Named Functions compared to Module Pattern without last module pattern

JavaScript performance comparison

Revision 24 of this test case created by max jooher

Info

Investigating the performance hit caused by nested functions.

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var Closure = (function() {
   
      var store;
   
      function inner(a) {
        store = a;
      };
   
      return {
   
        Nested: function(a) {
          function inner(a) {
            store = a;
          };
          inner(a);
        },
   
        Unnested: function(a) {
          inner(a)
        }
      }
    })();
   
   
    var flat;
   
    function Nested(a) {
      function inner(a) {
        flat = a;
      };
      inner(a);
    };
   
    function Unnested(a) {
      inner(a);
    }
   
    function inner(a) {
      flat = a;
    };
};
</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
Nested inside Closure
Closure.Nested(1);
pending…
Unnested inside Closure
Closure.Unnested(1);
pending…
Nested
Nested(1);
pending…
Unnested
Unnested(1);
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