jQuery append vs html vs innerHTML list performance (v75)

Revision 75 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>
<div id="list" style="display:none;height:0;overflow:hidden;">

Setup

var len = 10;

Test runner

Ready to run.

Testing in
TestOps/sec
jquery .append()
var html = '<div>';

for (var i = 0; i < len; i++) {
  html += '<div>Test ' + i + '</div>';
}

$('#list').append(html + '</div>');
ready
jQuery .html()
var html = '<div>';

for (var i = 0; i < len; i++) {
  html += '<div>Test ' + i + '</div>';
}

$('#list').html(html + '</div>');
ready
javascript innerHTML
var html = '<div>';
var list = document.getElementById('list');

for (var i = 0; i < len; i++) {
  html += '<div>Test ' + i + '</div>';
}

list.innerHTML = html + '</div>';
ready
jquery .append() dom
var html = $("<div/>");

for (var i = 0; i < len; i++) {
  html.append($('<div>Test ' + i + '</div>'));
}

$('#list').append(html);
ready

Revisions

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