cloneNode vs innerHTML redo

JavaScript performance comparison

Revision 4 of this test case created by Francis Avila

Preparation code

<div id="container" style="display: none;"></div>
<script>
Benchmark.prototype.setup = function() {
    var container = document.getElementById('container'),
        prototype = document.createElement('div'),
        copy, html = "<p>Adding some <strong>arbitrary</strong> HTML in here just to illustrate.</p> <p>Some <span>nesting</span> too.</p> <p>CloneNode doesn't care how the initial nodes are created.</p>";
   
    prototype.innerHTML = html;
};

Benchmark.prototype.teardown = function() {
    while (container.lastChild) container.removeChild(container.lastChild);
};
</script>

Preparation code output

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
el.cloneNode(true)
copy = prototype.cloneNode(true);
container.appendChild(copy);
pending…
append innerHTML copy
copy = document.createElement('div');
copy.innerHTML = prototype.innerHTML;
container.appendChild(copy);
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. Here’s a list of current revisions for this page:

0 comments

Add a comment