jQuery.append vs jQuery.html vs Element.innerHTML vs Element.insertAdjacentHTML list performance (v153)

Revision 153 of this benchmark created by Paul 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="height: 100px; overflow: auto;">
</div>

Setup

var list = document.getElementById('list');
    var $list = $(list);
    var len = 20;

Teardown


    list.innerHTML = '';
  

Test runner

Ready to run.

Testing in
TestOps/sec
jQuery.append()
for (var i = 0; i < len; i++) {
  var html = '<div>Test ' + i + '</div>';
  $list.append(html);
}
ready
jQuery.html()
for (var i = 0; i < len; i++) {
  var html = '<div>Test ' + i + '</div>';
  $list.html($list.html() + html);
}
ready
Element.innerHTML
for (var i = 0; i < len; i++) {
  var html = '<div>Test ' + i + '</div>';
  list.innerHTML += html;
}
ready
Element.insertAdjacentHTML
for (var i = 0; i < len; i++) {
  var html = '<div>Test ' + i + '</div>';
  list.insertAdjacentHTML('beforeend', html);
}
ready

Revisions

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