Adding HTML via JS

Benchmark created 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

Revisions

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