Document fragment vs innerHTML vs looped appendChild (v131)

Revision 131 of this benchmark created on


Preparation HTML

<div id="my-div">
</div>

Setup

var div = document.getElementById('my-div')

Teardown



            while (div.firstChild) div.removeChild(div.firstChild);
        
  

Test runner

Ready to run.

Testing in
TestOps/sec
Document fragment
var i = 0, fragment = document.createDocumentFragment();

while (i < 20) {
  var el = document.createElement('li');
  el.textContent= 'This is my list item number ' + i;
  fragment.appendChild(el);
i++; }

div.appendChild(fragment);
ready
innerHTML
var i = 0;

while (i < 20) {
  div.innerHTML += '<li>This is my list item number ' + i + '</li>';
i++; }
ready
Looped appendChild
var i = 0;

while (i < 20) {
  var el = document.createElement('li');
  el.innerText = 'This is my list item number ' + i;
  div.appendChild(el);
i++; }
ready

Revisions

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