Document fragment

JavaScript performance comparison

Revision 30 of this test case created by Ivan L

Preparation code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<div id='someElement'></div>
      
<script>
Benchmark.prototype.setup = function() {
  var append = function(container) {
    var divHeader = document.createElement("div");
    divHeader.id = "header";
    var divData = document.createElement("div");
    divData.id = "data";
    var divFooter = document.createElement("div");
    divFooter.id = "footer";
    container.appendChild(divHeader);
    container.appendChild(divData);
    container.appendChild(divFooter);
  };

};

Benchmark.prototype.teardown = function() {
  $('#someElement').empty()

};
</script>

Preparation code output

<div id='someElement'></div>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
No Fragment
var container = document.createElement("div");
container.id = "container";
append(container);
document.getElementById("someElement").appendChild(container);
pending…
Fragment
var container = document.createDocumentFragment();
container.id = "container";
append(container);
document.getElementById("someElement").appendChild(container);
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.

0 Comments