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

Revision 468 of this benchmark created by Aaditya Taparia on


Preparation HTML

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

Setup

document.getElementById('container').innerHTML = '<div id="box"><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></div>';
  var box = document.getElementById('box');

Test runner

Ready to run.

Testing in
TestOps/sec
removeChild(box.lastChild)
while (box.lastChild) {
  box.removeChild(box.lastChild);
}
ready
cloneNode(false)
box.replaceWith(box.cloneNode(false));
box = document.getElementById('box');
ready
removeChild(box.firstChild)
while (box.firstChild) {
  box.removeChild(box.firstChild);
}
ready
textContent = '';
box.textContent = '';
ready
innerHTML = ''
box.innerHTML = '';
ready

Revisions

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