Emptify element

JavaScript performance comparison

Revision 2 of this test case created by Nami

Info

gotta go fast

Preparation code

<div id="test-div"></div>
<script>
Benchmark.prototype.setup = function() {
    var i = 1000;
    var d = document;
    var div = d.getElementById('test-div');
    while(i--) {
      div.appendChild(d.createElement('span'));
      div.appendChild(d.createTextNode('test'));
    }
   
    var slice = [].slice;
};
</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 = null
div.innerHTML = null;
pending…
textContent = null
div.textContent = null;
pending…
firstChild
var node;
while (node = div.firstChild) {
  node.remove();
}
pending…
lastChild
var node;
while (node = div.lastChild) {
  node.remove();
}
pending…
innerHTML = ''
div.innerHTML = '';
pending…
textContent = ''
div.textContent = '';
pending…
parent.remove
div.parentNode.removeChild(div);
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