createElement vs cloneNode (v4)

Revision 4 of this benchmark created by Eamon Nerbonne on


Description

When creating many elements that are exactly the same, is it faster to create all manually or to create one and cloneNode() the rest?

Preparation HTML

<script>
  var createTable = (function(){
    var d=document;
    return function() {
      var tr, td, x, y, table = d.createElement('table');
      for (y = 0; y < 32; ++y) {
        tr = d.createElement('tr');
        for (x = 0; x < 32; ++x) {
          tr.appendChild(d.createElement('td'));
        }
        table.appendChild(tr);
      }
      return table;
    };
  })();
var cached = createTable();
var sink;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
createElement
sink = createTable();
 
ready
cloneNode
sink = cached.cloneNode(true);
 
ready

Revisions

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