textContent vs createTextNode() vs innerHTML

JavaScript performance comparison

Revision 22 of this test case created by

Preparation code

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

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

};

Benchmark.prototype.teardown = function() {
  target.innerHTML = '';

};
</script>

Preparation code output

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

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
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…
innerHTML
div.innerHTML = '1234';
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.

0 Comments