Single vs. Multiple jQuery Append

Benchmark created by Stephen on


Description

You can chain $.append(foo).append(bar).append(baz); in jQuery but is there a performance gain by doing the append() in a single step?

Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<table id="myTable"></table>

Setup

var loopCount = 100;

Test runner

Ready to run.

Testing in
TestOps/sec
Single Append
var str = '';
for(var i=0;i<loopCount;i++){
  str += '<tr><td>my data</td><td>more data</td></tr>';
}
$('#myTable').append(str);
ready
Multiple Appends
for(var i=0;i<loopCount;i++){
  $("#myTable").append('<tr>').append('<td>my data</td><td>more data</td>');
}
ready

Revisions

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