jQuery append vs html vs innerHTML list performance

JavaScript performance comparison

Revision 111 of this test case created

Info

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

Preparation code

<script src="//code.jquery.com/jquery-1.9.1.min.js">
</script>
<select id="list" ></select>
<script>
Benchmark.prototype.setup = function() {
    var len = 20;
    var html=[];
    for (var i = 0; i < len; i++) {
      html.push('<option value="'+ i +'">Test' + i + '</option>');
   
    }
   
    var htmlArrayObjects =[];
    for (var i = 0; i < len; i++) {
      html.push({label:'Test' + i,value:i}
    );
   
    }
   
   
    var htmlOption = '';
    for (var a = 0; a < len; a++) {
      htmlOption = htmlOption + '<option value="'+ a +'">Test' + a + '</option>';
   
    }
   
};
</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.join(''));
pending…
jQuery .html()
  $('#list').html(htmlOption );
 
pending…
javascript innerHTML
 $('#list').append(htmlOption );
 
pending…
Concat
 $('#list').html(html.join(''));
pending…
Manually new Options
for(i = 0; i < htmlArrayObjects.length; i++){
document.getElementById("list").options[i] = new Option(htmlArrayObjects.label,htmlArrayObjects.value);
                     }
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