innerHTML vs removeChild

JavaScript performance comparison

Revision 128 of this test case created by

Preparation code

<div id='box'></div>
      
<script>
Benchmark.prototype.setup = function() {
  var b = document.getElementById('box');
  for (var i = 0; i < 1000; i++) {
    b.appendChild(document.createElement('div'));
  }

};

Benchmark.prototype.teardown = function() {
  box.textContent = '';

};
</script>

Preparation code output

<div id='box'></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
textContent
box.textContent = '';
pending…
innerHTML
box.innerHTML = '';
pending…
removeChild/lastChild
while (box.lastChild) {
  box.removeChild(box.lastChild);
}
pending…
lastChild/remove
while (box.lastChild) {
  box.lastChild.remove();
}
pending…
removeChild/firstChild
while (box.firstChild) {
  box.removeChild(box.firstChild);
}
pending…
firstChild/remove
while (box.firstChild) {
  box.firstChild.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