documentFragment appendChild vs jquery append (v37)

Revision 37 of this benchmark created on


Preparation HTML

<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>

Teardown


    $('#test-area').empty();
  

Test runner

Ready to run.

Testing in
TestOps/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);
ready
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);
ready
jquery + static html
var html = "<div>";

//var i = 1;
//for (i; <= 100000; i++) {
html += "<p>jquery elements</p>";
//}
html += "</div>";
$('#test-area').html(html);
ready
javascript + static html
var html = "<div>"
//var i = 1;
//for (i; <= 100000; i++) {
html += "<p>raw javascript</p>";
//}
html += "</div>";
document.getElementById('test-area').innerHTML = html;
ready
JQuery
var jq_fragment = $('<div/>', {
  text: function() {
    //var i = 1;
    //for (i; <= 100000; i++) {
    var p = $('<p/>', {
      text: "jquery elements"
    }).appendTo(jq_fragment);

    //}
  }
}).appendTo('#test-area');
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.