innerHTML vs removeChild (v18)

Revision 18 of this benchmark created on


Description

what method for empty a element is faster ?

Preparation HTML

<div><div id='box'></div><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>'

Teardown


    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 n = box.parentNode;
n.removeChild(box);
var box = document.createElement('div');
box.id = 'box';
n.appendChild(box);
 
ready

Revisions

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