textContent vs createTextNode() vs innerHTML

JavaScript performance comparison

Revision 16 of this test case created

Preparation code

<div id="div">
</div>
<script>
Benchmark.prototype.setup = function() {
    var div = document.getElementById('div');
};

Benchmark.prototype.teardown = function() {
    document.getElementById('div').innerHTML = '';
};
</script>

Preparation code output

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
innerText
div.innerText = '1234';
pending…
createTextNode()
div.appendChild(document.createTextNode('1234'));
pending…
innerHTML
div.innerHTML = '1234';
pending…
textContent
div.textContent = '1234';
pending…
innerOlolo
div.innerOlolo = '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