textContent vs createTextNode() vs innerHTML

JavaScript performance comparison

Revision 8 of this test case created by Zibx

Preparation code

<div id="div">asdfghkkl</div>
<script>
Benchmark.prototype.setup = function() {
    var div = document.getElementById( 'div' ), doc = document,c=10000000000,textNode = div.childNodes[0];
};
</script>

Preparation code output

asdfghkkl

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
innerText
div.innerText= c++;
 
pending…
textContent
textNode.textContent = c++;
 
pending…
innerHTML
div.innerHTML = c++;
 
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