Emptify element

JavaScript performance comparison

Revision 6 of this test case created by Chen-Pang He

Info

gotta go fast

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

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
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…

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