innerHTML vs removeChild(A slightly lighter html)

JavaScript performance comparison

Revision 108 of this test case created by prashant sheoran

Preparation code

<div id='box'></div>
      
<script>
Benchmark.prototype.setup = function() {
  var box = document.getElementById('box');
  box.innerHTML = 'sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df'

};

Benchmark.prototype.teardown = function() {
  box.innerHTML = 'sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df'

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

1 Comment

prashant sheoran (revision owner) commented :

Edited orginal Testcase to show that innerHtml is slower even with a small document fragment.