Document fragment vs html element append

JavaScript performance comparison

Revision 10 of this test case created

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.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()
};

Benchmark.prototype.teardown = function() {
    container.innerHTML = "";
};
</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
    var i;

    for (i = 0; i < ITERATIONS; ++i) {
      frag.appendChild(document.createElement("li"));
    }

    container.appendChild(frag);
    pending…
    jQuery append
    var i;

    for (i = 0; i < ITERATIONS; ++i) {
      $container.append(document.createElement("li"));
    }
    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