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>
<style>#placehere{display:none;}</style>
<script>
Benchmark.prototype.setup = function() {
    target.innerHTML = '';
};
</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
Target < Element .textContent
var el = document.createElement( 'p' );
el.textContent = "THIS IS A TEST";
target.appendChild( el );
pending…
Target < Element < TextNode(Text)
var el = document.createElement( 'p' );
var tn = document.createTextNode('THIS IS A TEST');
el.appendChild( tn );
target.appendChild( el );
pending…
innerHTML (for cheaters)
target.innerHTML = '<p>THIS IS A TEST</p>';
 
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