createDocumentFragment vs appendChild on non-appended element

JavaScript performance comparison

Revision 13 of this test case created

Info

Justice

Preparation code

<form id="fform"></form>
<script>
window.fform = document.getElementById('fform')
</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
Normal Append
var form = document.createElement('form'),
    array = [
        document.createElement('input'),
        document.createElement('input'),
        document.createElement('input'),
        document.createElement('input')
    ], i;
   
for (i = 0; i < 4; i +=1)
{
    form.appendChild(array[i]);
}
   
document.body.appendChild(form);
document.body.offsetHeight;
document.body.removeChild(form);
pending…
Document Fragment+Form
var docfrag = document.createDocumentFragment(),
    array = [
        document.createElement('input'),
        document.createElement('input'),
        document.createElement('input'),
        document.createElement('input')
    ], i;

for (i = 0; i < 4; i +=1)
{
    docfrag.appendChild(array[i]);
}
 
document.body.appendChild(docfrag);
document.body.offsetHeight;
document.body.innerHTML = '';
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