jQuery append vs html vs innerHTML list performance (v49)

Revision 49 of this benchmark created 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/2.0.3/jquery.min.js">
</script>
<ul id="list">
</ul>
<div id="myDiv">
</div>

Setup

var len = 20;

Teardown


    $("#list").empty();
    $("#myDiv").empty();
  

Test runner

Ready to run.

Testing in
TestOps/sec
jquery .append()
for (var i = 0; i < len; i++) {
  $('#list').append($("<li></li>", {
    text: "Test " + i
  }));
}
ready
jQuery .html()
for (var i = 0; i < len; i++) {
  $('#list').append('<li>Test ' + i + '</li>');
}
ready
javascript innerHTML
var html = '';
for (var i = 0; i < len; i++) {
  html += '<div>Test ' + i + '</div>';
}

$('#list').get(0).innerHTML = html;
ready

Revisions

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