cloneNode vs createElement

JavaScript performance comparison

Revision 36 of this test case created by

Preparation code

<svg id="target"></svg>

<script>
  function generateNodes() {
    var el0 = document.createElement("polygon");
    el0.setAttribute("class", "section");
    el0.setAttribute("points", "472.7,595.1 344.2,582 272.7,591.9 195.4,583.1 104.5,612.4 44,659.7 56.5,665.2 109.8,618 196.5,588.2 272,598.9 344.2,586.1 472.7,599.7");
    return el0;
  }

  var div = generateNodes();

  var html = div.innerHTML;

  var target = document.getElementById('target');
</script>
      
<script>
Benchmark.prototype.teardown = function() {
  target.innerHTML = '';

};
</script>

Preparation code output

<svg id="target"></svg>

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
cloneNode()
var newDiv = div.cloneNode(true);
target.appendChild(newDiv);
pending…
createElement()
var newDiv = generateNodes();
target.appendChild(newDiv);
pending…
innerHTML
target.innerHTML = html;
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