innerHTML vs removeChild

JavaScript performance comparison

Revision 472 of this test case created by Mark Polak

Preparation code

<div id='box'></div>
      
<script>
Benchmark.prototype.setup = function() {
  var fragment = document.createDocumentFragment();
  var i = 1000;
  while (i) {
  var p = document.createElement('p');
      p.textContent = 'Lorem ipsum ' +  i;
      fragment.appendChild(p);
  i--;
  }
  var box = document.getElementById('box');
  box.appendChild(fragment.cloneNode(true));

};
</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
children.forEach
Array.prototype.slice.call(box.children)
        .forEach(node => box.removeChild(node));
pending…

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL.

0 Comments