jQuery append vs html vs innerHTML list performance (v139)

Revision 139 of this benchmark created by raul.arrieta 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>
<table id="test">
</table>

Setup

var nowNumber = 25;
    var columnNumber = 50;

Test runner

Ready to run.

Testing in
TestOps/sec
jquery .append()
var rows = '';
for (var i = 0; i < nowNumber; i++) {
  var tr = '<tr>';
  for (var j = 0; j < columnNumber; j++) {
    tr += '<td>&nbsp;</td>';
  }
  tr += '</tr>';
  rows += tr;
}
$('#test').empty().append(rows);
ready
jQuery .html()
var rows = '';
for (var i = 0; i < nowNumber; i++) {
  var tr = '<tr>';
  for (var j = 0; j < columnNumber; j++) {
    tr += '<td>&nbsp;</td>';
  }
  tr += '</tr>';
  rows += tr;
}
$('#test').html(rows);
ready
javascript innerHTML
var rows = '';
for (var i = 0; i < nowNumber; i++) {
  var tr = '<tr>';
  for (var j = 0; j < columnNumber; j++) {
    tr += '<td>&nbsp;</td>';
  }
  tr += '</tr>';
  rows += tr;
}
document.getElementById('test').innerHTML = rows;
ready

Revisions

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