Document fragment vs innerHTML vs looped appendChild (v47)

Revision 47 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
innerHTML
var i = 0;
var str='';
while (i < 20) {
  str += '<li>This is my list item number ' + i + '</li>';
i++; }
div.innerHTML=str;
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
Document fragment
var i = 0, fragment = document.createDocumentFragment();

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

div.appendChild(fragment);
ready

Revisions

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