Document fragment vs html element append

JavaScript performance comparison

Revision 11 of this test case created

Preparation code

<script src="//code.jquery.com/jquery-git2.min.js"></script>

<ul id="container"></ul>
<script>
Benchmark.prototype.setup = function() {
    var ITERATIONS = 1000;
    var container = document.getElementById("container");
    var $container = $("#container");
    var frag = document.createDocumentFragment();
    var clone1 = $container.clone();
    var clone2 = clone1;
};

Benchmark.prototype.teardown = function() {
    $("#container").empty();
    frag = document.createDocumentFragment();
    clone1 = clone2;
};
</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
    HTML element append
    for (var i = 0; i < ITERATIONS; ++i) {
      container.appendChild(document.createElement("li"));
    }
    pending…
    Fragment append
    for (var i = 0; i < ITERATIONS; ++i) {
      frag.appendChild(document.createElement("li"));
    }
    container.appendChild(frag);
    pending…
    jQuery append1
    for (var i = 0; i < ITERATIONS; ++i) {
      $container.append(document.createElement("li"));
    }
    pending…
    jQuery append2
    for (var i = 0; i < ITERATIONS; ++i) {
      clone1.append(document.createElement("li"));
    }
    $("#container").replaceWith(clone1);
    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