jQuery append vs html vs innerHTML list performance

JavaScript performance comparison

Revision 111 of this test case created by

Preparation code

<script src="https://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

<select id="list" ></select>

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 .append()
  $('#list').append(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…
jQuery .html()
  $('#list').html(htmlOption );
pending…
javascript innerHTML
 $('#list').append(htmlOption );
pending…
Concat
 $('#list').html(html.join(''));
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