innerHTML vs removeChild

JavaScript performance comparison

Revision 274 of this test case created by Mark

Preparation code

<div id='box'></div>
      
<script>
Benchmark.prototype.setup = function() {
  var box = document.getElementById('box');
  var boxHTML = new Array( 100 ).join( '<b>test</b><br /><p>test</p>' );

};
</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
removeChildFirst
box.innerHTML = boxHTML;

while (box.firstChild) {
  box.removeChild(box.firstChild);
}
pending…
innerHTML
box.innerHTML = boxHTML;

box.innerHTML = '';
pending…
removeChildLast
box.innerHTML = boxHTML;

while (box.lastChild) {
  box.removeChild(box.lastChild);
}
pending…
myRemove
box.innerHTML = boxHTML;

var last;
while (last = box.lastChild) {
  box.removeChild(last);
}
pending…
marcRemove
box.innerHTML = boxHTML;

while (!!box.lastChild) {
  box.removeChild(box.lastChild);
}
pending…
textContent
box.innerHTML = boxHTML;

box.textContent = '';
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