text content

JavaScript performance comparison

Revision 3 of this test case created by galambalazs

Info

Observation: .textContent ||.innerText order does matter in modern browsers. IE doesn't care, so put textContent first always.

Note: data, nodeValue and innerHTML are only included out of curiosity.

Preparation code

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

Preparation code output

content to be retrieved

Test runner

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

Java applet disabled.

Testing in unknown unknown
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. Here’s a list of current revisions for this page:

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

Add a comment