jQuery append vs html vs innerHTML list performance

JavaScript performance comparison

Revision 139 of this test case created by raul.arrieta

Preparation code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<table id="test">
</table>
      
<script>
Benchmark.prototype.setup = function() {
  var nowNumber = 25;
  var columnNumber = 50;

};
</script>

Preparation code output

<table id="test"> </table>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
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);
pending…
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);
pending…
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;
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.

0 Comments