textContent vs createTextNode() vs innerHTML vs nodeValue

JavaScript performance comparison

Revision 13 of this test case created by CoolCmd

Info

rev. 2 + nodeValue

Preparation code

<div id="div">asdfghkkl</div>
<script>
Benchmark.prototype.setup = function() {
    var div = document.getElementById( 'div' );
   
};
</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
textContent
div.textContent = '1234';
 
pending…
createTextNode()
div.removeChild( div.firstChild );
div.appendChild( document.createTextNode( '1234' ) );
pending…
innerHTML
div.innerHTML = '1234';
 
pending…
nodeValue
div.firstChild.nodeValue = '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. Here’s a list of current revisions for this page:

0 comments

Add a comment