textContent vs createTextNode() vs innerHTML

JavaScript performance comparison

Revision 23 of this test case created

Preparation code

<div id="placehere"></div>
<script>var target = document.getElementById('placehere');</script>
Benchmark.prototype.setup = function() {
    target.innerHTML = '';

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
Target < Element .textContent
var el = document.createElement( 'p' );
el.textContent = "THIS IS A TEST";
target.appendChild( el );
Target < Element < TextNode(Text)
var el = document.createElement( 'p' );
var tn = document.createTextNode('THIS IS A TEST');
el.appendChild( tn );
target.appendChild( el );
innerHTML (for cheaters)
target.innerHTML = '<p>THIS IS A TEST</p>';

Compare results of other browsers


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:


Comment form temporarily disabled.

Add a comment