documentFragment appendChild vs jquery append

JavaScript performance comparison

Revision 3 of this test case created by

Preparation code

<div id="test-area" style="height: 75px; width: auto; overflow:scroll">
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
      
<script>
Benchmark.prototype.teardown = function() {
  $('#test-area').empty();

};
</script>

Preparation code output

<div id="test-area" style="height: 75px; width: auto; overflow:scroll"> </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
raw javascript
var raw_fragment = document.createDocumentFragment();
//var i = 1;
//for (i; <= 100000; i++) {
var p = document.createElement("p");
p.appendChild(document.createTextNode("raw javascript, documentFragment"));
raw_fragment.appendChild(p);
//}
document.getElementById('test-area').appendChild(raw_fragment);
pending…
jquery
var jq_fragment = $('<div/>');

//var i = 1;
//for (i; <= 100000; i++) {
var p = $('<p/>');
p.append("jquery elements");
jq_fragment.append(p);
//}
$('#test-area').append(jq_fragment);
pending…
hybrid
var raw_fragment = $(document.createDocumentFragment());
var p = $('<p/>').append("jquery elements");
raw_fragment.append(p);
$('#test-area').append(raw_fragment);
pending…
jquery html
$('#test-area').html('<p>jquery elements</p>');
pending…
javascript html
document.getElementById('test-area').innerHTML = '<p>jquery elements</p>';
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