Document fragment vs innerHTML vs looped appendChild (v84)

Revision 84 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 < 200) {
  var el = document.createElement('li');
  el.innerText = 'This is my list item number ' + i;
  fragment.appendChild(el);
i++; }

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

while (i < 200) {
  result  += '<li>This is my list item number ' + i + '</li>';
i++; }

div.innerHTML = result
ready

Revisions

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