textContent vs createTextNode

JavaScript performance comparison

Revision 2 of this test case created by CoolCmd

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var s = document.createElement("span");
    var s2 = document.createElement("span");
    s2.textContent = " ";
};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
textContent
s.textContent = "foobar, foobar, foobar, foobar, foobar, foobar";
pending…
createTextNode
s.appendChild(document.createTextNode("foobar, foobar, foobar, foobar, foobar, foobar"));
pending…
textContent2
s2.textContent = "foobar, foobar, foobar, foobar, foobar, foobar";
pending…
nodeValue
s2.firstChild.nodeValue = "foobar, foobar, foobar, foobar, foobar, foobar";
pending…
createTextNode2
s2.replaceChild(document.createTextNode("foobar, foobar, foobar, foobar, foobar, foobar"), s2.firstChild);
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. Here’s a list of current revisions for this page:

0 comments

Add a comment