jQuery append vs html vs innerHTML list performance (v44)

Revision 44 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="//code.jquery.com/jquery-2.0.3.min.js"></script>
<ul id="list">
</ul>
<div id="myDiv">
</div>

Setup

var len = 200;

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>Test " + i + "</li>");
}
ready
jQuery .html()
var list = $('#list');
for (var i = 0; i < len; i++) {
  list.html(list.html() + '<li>Test ' + i + '</li>');
}
ready
javascript innerHTML
for (var i = 0; i < len; i++) {
  document.getElementById('list').innerHTML += '<div>Test ' + i + '</div>';
}
 
ready

Revisions

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