innerHTML vs removeChild (v20)

Revision 20 of this benchmark created by Grant Kiely on


Description

what method for empty a element is faster ?

Preparation HTML

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

Setup

var box = document.getElementById('box');
    box.innerHTML = '<h1>this is a heading<h1><div id="wrapper">Here is some cmmon content that you might find in a website</div><p>qesdafsdafdsa<p>testasingsda<p>tesa</p><h4>here is some more content<h4><h3>asdf</h3><div>more content</div><h1>this is a heading<h1><div id="wrapper">Here is some cmmon content that you might find in a website</div><p>qesdafsdafdsa<p>testasingsda<p>tesa</p><h4>here is some more content<h4><h3>asdf</h3><div>more content</div><h1>this is a heading<h1><div id="wrapper">Here is some cmmon content that you might find in a website</div><p>qesdafsdafdsa<p>testasingsda<p>tesa</p><h4>here is some more content<h4><h3>asdf</h3><div>more content</div><h1>this is a heading<h1><div id="wrapper">Here is some cmmon content that you might find in a website</div><p>qesdafsdafdsa<p>testasingsda<p>tesa</p><h4>here is some more content<h4><h3>asdf</h3><div>more content</div><h1>this is a heading<h1><div id="wrapper">Here is some cmmon content that you might find in a website</div><p>qesdafsdafdsa<p>testasingsda<p>tesa</p><h4>here is some more content<h4><h3>asdf</h3><div>more content</div><h1>this is a heading<h1><div id="wrapper">Here is some cmmon content that you might find in a website</div><p>qesdafsdafdsa<p>testasingsda<p>tesa</p><h4>here is some more content<h4><h3>asdf</h3><div>more content</div><h1>this is a heading<h1><div id="wrapper">Here is some cmmon content that you might find in a website</div><p>qesdafsdafdsa<p>testasingsda<p>tesa</p><h4>here is some more content<h4><h3>asdf</h3><div>more content</div><h1>this is a heading<h1><div id="wrapper">Here is some cmmon content that you might find in a website</div><p>qesdafsdafdsa<p>testasingsda<p>tesa</p><h4>here is some more content<h4><h3>asdf</h3><div>more content</div><h1>this is a heading<h1><div id="wrapper">Here is some cmmon content that you might find in a website</div><p>qesdafsdafdsa<p>testasingsda<p>tesa</p><h4>here is some more content<h4><h3>asdf</h3><div>more content</div><h1>this is a heading<h1><div id="wrapper">Here is some cmmon content that you might find in a website</div><p>qesdafsdafdsa<p>testasingsda<p>tesa</p><h4>here is some more content<h4><h3>asdf</h3><div>more content</div>';

Test runner

Ready to run.

Testing in
TestOps/sec
removeChild
while (box.firstChild) {
  box.removeChild(box.firstChild);
}
ready
removeChild 2
while (box.lastChild) {
  box.removeChild(box.lastChild);
}
ready
innerHTML
box.innerHTML = '';
ready
removeEntire
var pn = box.parentNode;
pn.removeChild(box);
var box = document.createElement('div');
box.id = 'box';
pn.appendChild(box);
ready

Revisions

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