Emptify element

JavaScript performance comparison

Revision 4 of this test case created by Nami

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

<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
if (!div.innerHTML.trim()) console.log('tis empty1');
div.innerHTML = null;
pending…
textContent
div.textContent = null;
pending…
firstChild
if (!div.innerHTML.trim()) console.log('tis empty3');
var node;
while (node = div.firstChild) {
  node.remove();
}
pending…
lastChild
var node;
while (node = div.lastChild) {
  node.remove();
}
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