jQuery.append vs jQuery.html vs Element.innerHTML vs Element.insertAdjacentHTML list performance

JavaScript performance comparison

Revision 153 of this test case created by Paul

Preparation code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<div id="list" style="height: 100px; overflow: auto;">
</div>
      
<script>
Benchmark.prototype.setup = function() {
  var list = document.getElementById('list');
  var $list = $(list);
  var len = 20;

};

Benchmark.prototype.teardown = function() {
  list.innerHTML = '';

};
</script>

Preparation code output

<div id="list" style="height: 100px; overflow: auto;"> </div>

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()
for (var i = 0; i < len; i++) {
  var html = '<div>Test ' + i + '</div>';
  $list.append(html);
}
pending…
jQuery.html()
for (var i = 0; i < len; i++) {
  var html = '<div>Test ' + i + '</div>';
  $list.html($list.html() + html);
}
pending…
Element.innerHTML
for (var i = 0; i < len; i++) {
  var html = '<div>Test ' + i + '</div>';
  list.innerHTML += html;
}
pending…
Element.insertAdjacentHTML
for (var i = 0; i < len; i++) {
  var html = '<div>Test ' + i + '</div>';
  list.insertAdjacentHTML('beforeend', html);
}
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