createDocumentFragment vs appendChild on non-appended element

JavaScript performance comparison

Revision 23 of this test case created

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></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
Straight DOM appendChild
var form = document.createElement('form');
document.body.appendChild(form);

for (var i = 0; i < 1000; i++) {
  form.appendChild(document.createElement('input'));
}

document.body.removeChild(form);
pending…
Document Fragment appendChild
var form = document.createElement('form');
document.body.appendChild(form);

var frag = document.createDocumentFragment();

for (var i = 0; i < 1000; i++) {
  frag.appendChild(document.createElement('input'));
}

form.appendChild(frag);

document.body.removeChild(form);
pending…
jQuery Append
var form = $('form');
$(document.body).append(form);

for (var i = 0; i < 1000; i++) {
  form.append($('input'));
}

form.remove();
pending…
InnerHTML Naive
var form = document.createElement('form');
document.body.appendChild(form);

for (var i = 0; i < 1000; i++) {
  form.innerHTML += "<input></input>";
}
pending…
InnerHTML Batch
var form = document.createElement('form');
document.body.appendChild(form);

var html = ""
for (var i = 0; i < 1000; i++) {
  html += "<input></input>";
}
form.innerHTML += html;
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