cloneNode vs createElement Performance

JavaScript performance comparison

Revision 81 of this test case created by SAMZLab

Preparation code

<script>
  var img = document.createElement("img");
  img.src = "https://www.google.com/intl/en_com/images/srpr/logo2w.png";
  
  var div = document.createElement("div");
  div.className = "myclass1 myclass2";

  function createHTMLNode(){
      var wrap = document.createElement("div");
      wrap.innerHTML = '<div class="test"><img src="https://www.google.com/intl/en_com/images/srpr/logo2w.png"><span>lorem ipsum</span></div>';
      return wrap.children[0];
  }
  function createDepthNode(){
    var depthNode = document.createElement("div"),
        depthImage = document.createElement("img"),
        depthSpan = document.createElement("span"),
        depthText = document.createTextNode("lorem ipsum");
    depthNode.setAttribute("class", "test")
    depthImage.setAttribute("src", "https://www.google.com/intl/en_com/images/srpr/logo2w.png")
    depthNode.appendChild(depthImage);
    depthSpan.appendChild(depthText);
    depthNode.appendChild(depthSpan)
    return depthNode;
  }
  var depthNode = createDepthNode();

  var input = document.createElement("input");
  input.type = "checkbox";
  input.class = "myinputclass";
</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
depth node from html
var depthFromHTML = createHTMLNode();
pending…

Revisions

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

0 Comments