cloneNode vs createElement Performance

JavaScript performance comparison

Revision 30 of this test case created by Larry Davis

Preparation code

<script>
  function generateNodes() {
    var el0 = document.createElement("section");
    el0.setAttribute("class", "section");
    var el2 = document.createElement("header");
    el2.setAttribute("class", "header");
    el2.textContent = "Header";
    el0.appendChild(el2);
    var el4 = document.createElement("article");
    el4.setAttribute("class", "article");
    var el6 = document.createElement("p");
    el6.textContent = "Paragraph 1";
    el4.appendChild(el6);
    var el8 = document.createElement("p");
    el8.textContent = "Paragraph 2";
    el4.appendChild(el8);
    var el10 = document.createElement("p");
    el10.textContent = "Paragraph 3";
    el4.appendChild(el10);
    var el12 = document.createElement("p");
    el12.textContent = "Paragraph 4";
    el4.appendChild(el12);
    var el14 = document.createElement("p");
    el14.textContent = "Paragraph 5";
    el4.appendChild(el14);
    var el16 = document.createElement("ul");
    el16.setAttribute("class", "list");
    var el18 = document.createElement("li");
    el18.textContent = "Item 1";
    el16.appendChild(el18);
    var el20 = document.createElement("li");
    el20.textContent = "Item 2";
    el16.appendChild(el20);
    var el22 = document.createElement("li");
    el22.textContent = "Item 3";
    el16.appendChild(el22);
    var el24 = document.createElement("li");
    el24.textContent = "Item 4";
    el16.appendChild(el24);
    var el26 = document.createElement("li");
    el26.textContent = "Item 5";
    el16.appendChild(el26);
    el4.appendChild(el16);
    el0.appendChild(el4);
    var el30 = document.createElement("footer");
    el30.setAttribute("class", "footer");
    el30.textContent = "Footer";
    el0.appendChild(el30);
    return el0;
  }

  var div = generateNodes();
</script>
    

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
Clone structure
var newDiv = div.cloneNode(true);
pending…
Create structure
var newDiv = generateNodes();
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