innerHTML vs document fragment

Benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
innerHTML
(function() {
 var i = 2000,
     container = document.createElement("div"),
     html = "";
 while (i--) html += "<div></div>";
 container.innerHTML = html;
}());
ready
document fragment
(function() {
 var i = 2000,
     container = document.createElement("div"),
     frag = document.createDocumentFragment();
 while (i--) frag.appendChild(document.createElement("div"));
 container.appendChild(frag);
}());
ready

Revisions

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