Removing DOM Children: While / Reverse For Loop

Benchmark created by Matt McDonald 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 i = (el.childNodes.length - 1); i > -1; i--) {
 el.removeChild(el.firstChild);
}
ready

Revisions

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