Adding HTML via JS (v3)

Revision 3 of this benchmark created by Tester on


Preparation HTML

<div id="demoId">
</div>

Test runner

Ready to run.

Testing in
TestOps/sec
innerHTML
// Clear out the HTML (the same on both)
document.getElementById('demoId').innerHTML = '';

document.getElementById('demoId').innerHTML = '<div>hello world and <a>click me</a> also</div>';
ready
createElement
// Clear out the HTML (the same on both)
document.getElementById('demoId').innerHTML = '';

var itd = document.createElement('div'),
    ita = document.createElement('a'),
    idt = document.createTextNode('hello world');
iat = document.createTextNode('click me');
idn = document.createTextNode('also');

ita.appendChild(iat);
itd.appendChild(idt);
itd.appendChild(ita);
itd.appendChild(idn)

document.getElementById('demoId').appendChild(itd);
ready
createElement with document precached
// Clear out the HTML (the same on both)
var doc = document;
doc.getElementById('demoId').innerHTML = '';

var itd = doc.createElement('div'),
    ita = doc.createElement('a'),
    idt = doc.createTextNode('hello world');
iat = doc.createTextNode('click me');
idn = doc.createTextNode('also');

ita.appendChild(iat);
itd.appendChild(idt);
itd.appendChild(ita);
itd.appendChild(idn)

doc.getElementById('demoId').appendChild(itd);
ready

Revisions

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