Emptify element

JavaScript performance comparison

Revision 7 of this test case created by

Preparation code

<div id="test-div"></div>
      
<script>
Benchmark.prototype.setup = function() {
  var i = 1000;
  var div = document.getElementById('test-div');
  var span;
  
  while(i--) {
    span = document.createElement('span');
    span.appendChild(document.createTextNode('test'));
    div.appendChild(span);
  }

};
</script>

Preparation code output

<div id="test-div"></div>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
innerHTML
div.innerHTML = null;
pending…
textContent
div.textContent = null;
pending…
firstChild
var node;
while (node = div.firstChild) {
  div.removeChild(node);
}
pending…
lastChild
var node;
while (node = div.lastChild) {
  div.removeChild(node);
}
pending…
nextSibling
var n1, n2;
for (n2 = div.firstChild; n1 = n2; ) {
  n2 = n1.nextSibling;
  div.removeChild(n1);
}
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.

0 Comments