jQuery append vs html vs innerHTML list performance

JavaScript performance comparison

Revision 15 of this test case created by Adam

Info

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

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<div id="list" style="height:400px;overflow-y:scroll;">
</div>
<script>
Benchmark.prototype.setup = function() {
    var len = 20;
    var elems = [];
    var html = '';
    for (var i = 0; i < len; i++) {
      elems += $('<div>Test ' + i + '</div>');
      html += '<div>Test ' + i + '</div>';
    }
   
};

Benchmark.prototype.teardown = function() {
    $('#list').empty();
};
</script>

Preparation code output

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
jquery .append()
$('#list').append(html);
pending…
jQuery .html()
$('#list').html(html);
pending…
javascript innerHTML
document.getElementById('list').innerHTML = html;
pending…
jquery .append() single
for (var i = 0; i < len; i++) {
  $('#list').append('<div>Test ' + i + '</div>');
}
pending…
jquery .append() single $
for (var i = 0; i < len; i++) {
  $('#list').append(elems[i]);
}
pending…
jquery .append() $
$('#list').append(elems);
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment