Nab

JavaScript performance comparison

Revision 10 of this test case created

Info

Demonstrating the performance hit caused by nested functions.

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<script>
  function a() {
    for (var i = 0; i < 10; i++) {
      $("body").append("<div>a" + i + "</div>");
    }
  }

  function b() {
    var j = "";
    for (var i = 0; i < 10; i++) {
      j += "<div>a" + i + "</div>";
    }
    $("#d1").append(j);
  }
</script>

Preparation code output

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)
a();
pending…
Nested Function
b();
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