remove children

JavaScript performance comparison

Revision 208 of this test case created

Info

what method for empty a element is faster ?

Preparation code

<div id='wrap'>
<div id='box'></div>
</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>";
    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
remove firstChild
write();
while (box.firstChild) {
  box.removeChild(box.firstChild);
}
pending…
set empty innerHTML
write();
box.innerHTML = '';
pending…
set empty innerText
write();
box.innerText = '';
pending…
Test 1, avoiding repaint
write();
box.style.display='none';
box.innerHTML = '';
box.style.display='';

 
pending…
cloneNode
write();
var dupNode = box.cloneNode(false);
box.parentNode.replaceChild(dupNode, box);
 
pending…
remove firstchild in while
write();
while (box.removeChild(box.firstChild))
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