Replace text in node (v2)

Revision 2 of this benchmark created on


Preparation HTML

<div id="something">old text</div>

Test runner

Ready to run.

Testing in
TestOps/sec
innerHTML
document.getElementById("something").innerHTML = "new text";
ready
DOM traversing
var element = document.getElementById('something');

// removing everything inside the node
while (element.firstChild) {
    element.removeChild(element.firstChild);
}

// appending new text node
element.appendChild(document.createTextNode('new text'));
ready
DOM traversing backwards
var element = document.getElementById('something');

// removing everything inside the node
while (element.lastChild) {
    element.removeChild(element.lastChild);
}

// appending new text node
element.appendChild(document.createTextNode('new text'));
ready

Revisions

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