text content (v11)

Revision 11 of this benchmark created on


Preparation HTML

<div id="text">content to be retrieved</div>
<script>
  var elem = document.getElementById("text");
  var elem2 = document.createElement('div');
  var preTextNode = document.createTextNode('Hello there');
</script>

Setup

elem2 = document.createElement('div');
    elem.innerHTML = 'content to be retrieved';

Teardown


    elem2 = document.createElement('div');
    elem.innerHTML = 'content to be retrieved';
  

Test runner

Ready to run.

Testing in
TestOps/sec
read innerHTML
var x = elem.innerHTML;
ready
read textContent
var x = elem.textContent;
ready
read data
var x = elem.firstChild.data;
ready
write innerHTML
elem.innerHTML = 'written content'
ready
write textContent
elem.textContent = 'written content'
ready
write data
elem.firstChild.data = 'written content'
ready
write data w/ check
if (elem.firstChild) elem.firstChild.data = 'written content';
ready
write data w/ check 2
if (elem2.firstChild)
  elem2.firstChild.data = 'written content';
else
  elem2.appendChild(document.createTextNode('written content'));
ready
write data w/o check 2
elem2.appendChild(document.createTextNode('written content'));
ready
write data w/o check 2b
elem2.appendChild(preTextNode);
ready
write data w/o check 3b
elem.replaceChild(preTextNode,elem.firstChild);
ready
write data w/ check 2+
if (elem2.firstChild)
  elem2.firstChild.data = preTextNode.data;
else
  elem2.appendChild(preTextNode);
ready
replace w/ string
var tmpNode = document.createTextNode('written content');
elem.replaceChild(tmpNode,elem.firstChild);
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.

  • Revision 1: published by galambalazs on
  • Revision 2: published by galambalazs on
  • Revision 3: published by galambalazs on
  • Revision 9: published by aeosynth on
  • Revision 10: published by Mayhem on
  • Revision 11: published on