Fastest method of clearing all children from a DOM element (v462)

Revision 462 of this benchmark created by T. H. Doan on


Preparation HTML

<div id="container"></div>

Setup

document.getElementById('container').innerHTML = '<div id="box"></div>';
  var box = document.getElementById('box');
  box.innerHTML = '<span>Abc123</span><span>Abc123</span><span>Abc123</span><span>Abc123</span><span>Abc123</span><span>Abc123</span><span>Abc123</span><span>Abc123</span><span>Abc123</span><span>Abc123</span><span>Abc123</span><span>Abc123</span><span>Abc123</span><span>Abc123</span><span>Abc123</span><span>Abc123</span><span>Abc123</span><span>Abc123</span><span>Abc123</span><span>Abc123</span><span>Abc123</span><span>Abc123</span><span>Abc123</span><span>Abc123</span><span>Abc123</span><span>Abc123</span>';

Test runner

Ready to run.

Testing in
TestOps/sec
innerHTML = ''
box.innerHTML = '';
ready
removeChild(box.lastChild)
while (box.lastChild) {
  box.removeChild(box.lastChild);
}
ready
children[0].remove()
while (box.children.length) {
  box.children[0].remove();
}
ready
cloneNode(false)
var clone = box.cloneNode(false);
box.parentNode.replaceChild(clone, box);
ready
removeChild(box.firstChild)
while (box.firstChild) {
  box.removeChild(box.firstChild);
}
ready

Revisions

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