textContent vs createTextNode() vs innerHTML

JavaScript performance comparison

Revision 21 of this test case created

Preparation code

<div id="placehere"></div>

<script>
var target = document.getElementById( 'placehere' )
,   el
,   tn
;
</script>
<script>
Benchmark.prototype.teardown = function() {
    target.removeChild( el );
};
</script>

Preparation code output

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
el = document.createElement( 'p' );
el.textContent = "THIS IS A TEST";
target.appendChild( el );
pending…
createTextNode()
el = document.createElement( 'p' );
tn = document.createTextNode('THIS IS A TEST');
el.appendChild( tn );
target.appendChild( el );
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