documentFragment appendChild vs jquery append

JavaScript performance comparison

Revision 16 of this test case created

Preparation code

<div id="test-area" style="height: 75px; width: auto; overflow:scroll">
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<script>
Benchmark.prototype.teardown = function() {
    $('#test-area').empty();
};
</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
Document Fragment
var raw_fragment = document.createDocumentFragment();

//var i = 10000;
//while (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 = [];

//var i = 10000;
//while (i--) {
  jq_fragment.push("<p>jquery elements</p>");
//}

$('#test-area').append(jq_fragment.join(""));
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