DOM vs innerHTML

JavaScript performance comparison

Revision 10 of this test case created by gonchuki

Preparation code

<div id="main_node"></div>
<script>
  var node = document.getElementById('main_node'),
      fragment = document.createDocumentFragment();
</script>
    

Preparation code output

<div id="main_node"></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
DOM
fragment.appendChild(document.createElement('div'));
fragment.appendChild(document.createElement('div'));
fragment.appendChild(document.createElement('div'));
fragment.appendChild(document.createElement('div'));
fragment.appendChild(document.createElement('div'));
fragment.appendChild(document.createElement('div'));
fragment.appendChild(document.createElement('div'));
fragment.appendChild(document.createElement('div'));
fragment.appendChild(document.createElement('div'));
fragment.appendChild(document.createElement('div'));
fragment.appendChild(document.createElement('div'));
fragment.appendChild(document.createElement('div'));
fragment.appendChild(document.createElement('div'));
fragment.appendChild(document.createElement('div'));
fragment.appendChild(document.createElement('div'));
fragment.appendChild(document.createElement('div'));
fragment.appendChild(document.createElement('div'));
fragment.appendChild(document.createElement('div'));
fragment.appendChild(document.createElement('div'));
fragment.appendChild(document.createElement('div'));
fragment.appendChild(document.createElement('div'));
fragment.appendChild(document.createElement('div'));
fragment.appendChild(document.createElement('div'));
fragment.appendChild(document.createElement('div'));
fragment.appendChild(document.createElement('div'));
fragment.appendChild(document.createElement('div'));
fragment.appendChild(document.createElement('div'));
fragment.appendChild(document.createElement('div'));
fragment.appendChild(document.createElement('div'));
fragment.appendChild(document.createElement('div'));
fragment.appendChild(document.createElement('div'));
fragment.appendChild(document.createElement('div'));
fragment.appendChild(document.createElement('div'));
fragment.appendChild(document.createElement('div'));
fragment.appendChild(document.createElement('div'));
fragment.appendChild(document.createElement('div'));
fragment.appendChild(document.createElement('div'));
fragment.appendChild(document.createElement('div'));
fragment.appendChild(document.createElement('div'));
fragment.appendChild(document.createElement('div'));

node.appendChild(fragment);

node.innerHTML = '';
pending…
innerHTML
node.innerHTML = '<div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div>';

node.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.

0 Comments