Removing DOM Children: While / Reverse For Loop (v3)

Revision 3 of this benchmark created on


Description

Testing a "remove all child nodes" function via a while loop or a reverse for loop

Preparation HTML

<div id="box">
    test
    test
    test
    test
    test
    test
    test
</div>
<script>
  var el = document.getElementById("box");
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
While Loop
while (el.firstChild) {
 el.removeChild(el.firstChild);
}
ready
For Loop
for (var cnLength=el.childNodes.length-1,i = (cnLength - 1); i > -1; i--) {
 el.removeChild(el.lastChild);
}
ready

Revisions

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