Document fragment vs innerHTML vs looped appendChild (v8)

Revision 8 of this benchmark created on


Preparation HTML

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

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;

while (i < 20) {
  div.innerHTML += '<path d="M 1 1 L 6 6">' + '</li>';
  i++;
}
ready
Looped appendChild
var i = 0;

while (i < 20) {
  var el = document.createElementNS("http://www.w3.org/2000/svg", "path");
  el.setAttribute("d", "M 1 1 L 6 6");
  div.appendChild(el);
  i++;
}
ready
Document fragment
var i = 0,
  fragment = document.createDocumentFragment();

while (i < 20) {
  var el = document.createElementNS("http://www.w3.org/2000/svg", "path");
  el.setAttribute("d", "M 1 1 L 6 6");
  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.