innerHTML vs removeChild (v274)

Revision 274 of this benchmark created by Mark on


Preparation HTML

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

Setup

var box = document.getElementById('box');
  var boxHTML = new Array( 100 ).join( '<b>test</b><br /><p>test</p>' );

Test runner

Ready to run.

Testing in
TestOps/sec
removeChildFirst
box.innerHTML = boxHTML;

while (box.firstChild) {
  box.removeChild(box.firstChild);
}
ready
innerHTML
box.innerHTML = boxHTML;

box.innerHTML = '';
ready
removeChildLast
box.innerHTML = boxHTML;

while (box.lastChild) {
  box.removeChild(box.lastChild);
}
ready
myRemove
box.innerHTML = boxHTML;

var last;
while (last = box.lastChild) {
  box.removeChild(last);
}
ready
marcRemove
box.innerHTML = boxHTML;

while (!!box.lastChild) {
  box.removeChild(box.lastChild);
}
ready
textContent
box.innerHTML = boxHTML;

box.textContent = '';
ready

Revisions

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