jQuery append vs html vs innerHTML list performance

JavaScript performance comparison

Revision 167 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>
<select id="list1" ></select>
<select id="list2" ></select>
<select id="list3" ></select>
<select id="list4" ></select>
      
<script>
Benchmark.prototype.setup = function() {
  var val= 0;

};

Benchmark.prototype.teardown = function() {
  var val= 0;

};
</script>

Preparation code output

<select id="list" ></select> <select id="list1" ></select> <select id="list2" ></select> <select id="list3" ></select> <select id="list4" ></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
new option
for(i = 0; i < 5000; i++){
option = new Option(val, val++);
option.setAttribute('data-test', val);
list1[list1.length]=option;
}
pending…
append innerHTML
for(i = 0; i < 5000; i++){
list1.innerHTML='<option value="'+val+ 'data-test='+val+'>'+val++ +'</option>';
}
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