document.write VS. document.createElement (v12)

Revision 12 of this benchmark created by Addy Osmani on


Description

A performance comparison of document.write VS document.createElement

Preparation HTML

<div id="foo" style="display: none;"></foo>
<iframe id="bar" style="display: none"></iframe>

Setup

foo = document.getElementById("foo");
    bar = document.getElementById("bar");
    bar_doc = (bar.contentWindow.document || bar.contentDocument.document);

Test runner

Ready to run.

Testing in
TestOps/sec
document.write
var newHTML = "<div><h1>Testing</h1></div>";
bar_doc.write(newHTML);
ready
document.createElement
var newDiv = document.createElement("div");
newDiv.innerHTML = "<h1>Testing</h1>";
foo.appendChild(newDiv);
ready

Revisions

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