documentFragment appendChild vs jquery append (v29)

Revision 29 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; i <= 100; i++) {
var p = document.createElement("p");
p.className = 'test';
p.setAttribute('title', 'test');
$(p).click(function(){console.log();});
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; i <= 100; i++) {
var p = $('<p class="test" title="test"/>');
p.click(function(){console.log();});
p.append("jquery elements");
jq_fragment.append(p);
}
$('#test-area').append(jq_fragment);
ready
hybrid
var raw_fragment = $(document.createDocumentFragment());
var i = 1;
for (i; i <= 100; i++) {
var p = $('<p class="test" title="test"/>').append("jquery elements");
p.click(function(){console.log();});
raw_fragment.append(p);
}
$('#test-area').append(raw_fragment);
ready
jquery html
$('#test-area').html(new Array(100 + 2).join('<p class="test" title="test">jquery elements</p>'));
$('#test-area p').click(function(){console.log();});
ready
javascript html
document.getElementById('test-area').innerHTML = new Array(100 + 2).join('<p class="test" title="test">jquery elements</p>');
$('#test-area p').click(function(){console.log();});
ready

Revisions

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