Nested Named Functions

JavaScript performance comparison

Test case created by Jeremy McPeak (Nettuts)

Info

Demonstrating the performance hit caused by nested functions.

Preparation code

<script>
  function foo(a, b) {
    function bar() {
      return a + b;
    }
 
    return bar();
  }
 
  function foo2(a, b) {
    return bar2(a, b);
  }
 
  function bar2(a, b) {
    return a + b;
  }
</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
Optimized (No Nesting)
foo2();
pending…
Nested Function
foo();
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