cloneNode vs innerHTML redo
JavaScript performance comparison
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.
| Test | Ops/sec | |
|---|---|---|
el.cloneNode(true) |
|
pending… |
append innerHTML 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:
- Revision 1: published
- Revision 2: published
- Revision 4: published by Francis Avila
0 comments