InnerHTML vs DOM Manipulation 2 (v2)

Revision 2 of this benchmark created on


Preparation HTML

<div>
  <div id="main"></div>
</div>
<script src="https://raw.github.com/olado/doT/master/doT.min.js"></script>

Setup

var s = [
      "<table class=\"editor\">",
        "{{ var i = 15; while (i--) { }}",
          "<tr>",
            "{{ var j = 23; while (j--) { }}",
              "<td>{{= it.data }}</td>",
            "{{ } }}",
          "</tr>",
        "{{ } }}",
      "</table>"
    ].join("");
    
    var template = doT.template(s);
    var container = document.getElementById("main");

Teardown


    while (container.hasChildNodes()) {
      container.removeChild(container.lastChild);
    }
  

Test runner

Ready to run.

Testing in
TestOps/sec
InnerHTML Insert
container.innerHTML = template({data: "...."});
ready
DOM Append
var table = document.createElement("table");
table.className = "editor";
var i = 15;
var j = 23;
while (i--) {
  var row = document.createElement("tr");
  while (j--) {
    var cell = document.createElement("td");
    cell.innerText = "....";
    row.appendChild(cell);
  }
  table.appendChild(row);
  j = 23;
}
container.appendChild(table);
ready

Revisions

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

  • Revision 1: published by Nick Thompson on
  • Revision 2: published on