out of dom vs documentfragment (v2)

Revision 2 of this benchmark created by rmaksim on


Preparation HTML

<div id="list1">
</div>
<div id="list2">
</div>
<div id="list3">
</div>

Test runner

Ready to run.

Testing in
TestOps/sec
out of dom
var list = document.getElementById('list1'),
    elem = document.createElement('div');

list.innerHTML = "";
for (var i = 0; i < 100; i++) {
  a = document.createElement('a');
  a.setAttribute("href", "#");
  a.innerHTML = 'link ' + i;
  a.style.display = 'block';
  elem.appendChild(a);
}
list.appendChild(elem);
ready
documentfragment
var list = document.getElementById('list2'),
    elem = document.createDocumentFragment();

list.innerHTML = "";
for (var i = 0; i < 100; i++) {
  a = document.createElement('a');
  a.setAttribute("href", "#");
  a.innerHTML = 'link ' + i;
  a.style.display = 'block';
  elem.appendChild(a);
}
list.appendChild(elem);
ready
innerHTML
var list = document.getElementById('list3'),
    elems = "";

list.innerHTML = "";
for (var i = 0; i < 100; i++) {
  elems += '<a href="#" style="display:block;">link ' + i + '</a>';
}
list.innerHTML = elems;
ready

Revisions

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