innerHTML vs removeChild

JavaScript performance comparison

Revision 142 of this test case created by empty

Info

what method for empty a element is faster ?

Preparation code

<div id='box'></div>
<script>
Benchmark.prototype.setup = function() {
    function write()
    {
     var box = document.getElementById('box');
    var div = document.createElement('div');
    div.innerHTML = "halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>halo <br> des <div>aaaa</div><table></table>";
    box.appendChild(div);
   
    }
};
</script>

Preparation code output

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
removeChild
write();
while (box.firstChild) {
  box.removeChild(box.firstChild);
}
pending…
innerHTML
write();
box.innerHTML = '';
pending…
innerText
write();
box.innerText = '';
pending…
withoutDom
write();
box.style.display='none';
box.innerHTML = '';
box.style.display='';

 
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment