text content

JavaScript performance comparison

Revision 3 of this test case created by galambalazs

Preparation code

<div id="text">content to be retrieved</div>
<script>
  var elem = document.getElementById("text");
  var node = elem.firstChild;
</script>
    

Preparation code output

<div id="text">content to be retrieved</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
innerHTML
var x = elem.innerHTML;
pending…
textContent || innerText
var x = elem.textContent || elem.innerText;
pending…
innerText || textContent
var x = elem.innerText || elem.textContent;
pending…
data
var x = node.data;
pending…
nodeValue
var x = node.nodeValue;
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.

1 Comment

galambalazs (revision owner) commented :

Notice how huge the difference can be:

  • 60x in Chrome
  • 10x in Safari 5, Firefox 3.6
  • 3x in Firefox 4.0b
content to be retrieved