innerHTML vs removeChild (v128)

Revision 128 of this benchmark created on


Description

what method for empty a element is faster ?

Preparation HTML

<div id='box'></div>

Setup

var b = document.getElementById('box');
    for (var i = 0; i < 1000; i++) {
      b.appendChild(document.createElement('div'));
    }

Teardown


    box.textContent = '';
  

Test runner

Ready to run.

Testing in
TestOps/sec
textContent
box.textContent = '';
ready
innerHTML
box.innerHTML = '';
ready
removeChild/lastChild
while (box.lastChild) {
  box.removeChild(box.lastChild);
}
ready
lastChild/remove
while (box.lastChild) {
  box.lastChild.remove();
}
ready
removeChild/firstChild
while (box.firstChild) {
  box.removeChild(box.firstChild);
}
 
ready
firstChild/remove
while (box.firstChild) {
  box.firstChild.remove();
}
 
ready

Revisions

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