Emptify element

JavaScript performance comparison

Revision 9 of this test case created by Zixaphir

Info

gotta go fast

Apparently each test "loop" is a single sample?

Preparation code

<div id="test-div"></div>
<script>
var div = document.getElementById('test-div'),
reallocate = function() {
  var i = 1000;
  var span;

  while (i--) {
    span = document.createElement('span');
    span.appendChild(document.createTextNode('test'));
    div.appendChild(span);
  }
};
</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
innerHTML
reallocate();
div.innerHTML = '';
pending…
textContent
reallocate();
div.textContent = '';
pending…
firstChild
reallocate();
var node;
while (node = div.firstChild) {
  div.removeChild(node);
}
pending…
lastChild
reallocate();
var node;
while (node = div.lastChild) {
  div.removeChild(node);
}
pending…
nextSibling
reallocate();
var n1, n2;
for (n2 = div.firstChild; n1 = n2;) {
  n2 = n1.nextSibling;
  div.removeChild(n1);
}
pending…
Recreate
reallocate();
ndiv = div.cloneNode(false);
div.parentNode.replaceChild(ndiv, div);
div = ndiv;
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