jQuery .html() vs .empty().append() (v17)

Revision 17 of this benchmark created on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<div id="test"></div>

Test runner

Ready to run.

Testing in
TestOps/sec
.html()
var $test = $("#test");
var tpl = '';
for (var i = 0; i < 1000; i++) {
  tpl += '<div class="some-class' + i + '"><span></span><div></div></div>';  
}

$test.append(tpl);
ready
.empty().append()
var $test = $("#test");
var tpl = '';
for (var i = 0; i < 1000; i++) {
  tpl += '<div class="some-class' + i + '"><span></span><div></div></div>';  
}
var frag = document.createDocumentFragment();
frag.innerHTML = tpl;
$test.get(0).appendChild(frag);
ready

Revisions

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