jQuery append vs html vs innerHTML list performance (v28)

Revision 28 of this benchmark created by mekwall on


Description

Just a simple example showing the speed difference between populating a list with .append() & .html() and innerHTML

Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<div id="list" style="display:none">
</div>

Setup

var len = 20;

Test runner

Ready to run.

Testing in
TestOps/sec
jQuery.append()
for (var i = 0; i < len; i++) {
  $('#list').append('<div>Test ' + i + '</div>');
}
ready
jQuery.html()
var html = "";
for (var i = 0; i < len; i++) {
  html += '<div>Test ' + i + '</div>';
}
$('#list').html(html);
ready
innerHTML with concat
var list = document.getElementById('list');
var html = "";
for (var i = 0; i < len; i++) {
   html += '<div>Test ' + i + '</div>';
}
list.innerHTML = html;
ready
innerHTML with array
var list = document.getElementById('list');
var html = [];
for (var i = 0; i < len; i++) {
  html.push('<div>Test ' + i + '</div>');
}
list.innerHTML = html.join('');
ready

Revisions

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