removeChildren

JavaScript performance comparison

Test case created by Nikita Vasilyev and last updated

Info

From http://elv1s.ru/files/html+css/removeChildren.html

Note: This test is incorrect. After the first test empties element, it is not restored again, so obviously all tests after that will be über fast. See revision 3 for a fair version of this test.

Preparation code

<script>
  var element = window.element = document.createElement("div");
  var i = 2000;
  while (i--) {
   var p = document.createElement("p")
   var j = 5;
   while (j--) {
    var span = document.createElement("span")
    span.appendChild(document.createTextNode(i * j + "yada-yada"))
    p.appendChild(span)
   }
   element.appendChild(p)
  }
  document.body.appendChild(element)
</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
innerHTML
element.innerHTML = ""
pending…
textContent
element.textContent = ""
pending…
removeFirstChild
var child
while (child = element.firstChild) {
 element.removeChild(child)
}
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