createDocumentFragment vs appendChild on non-appended element

JavaScript performance comparison

Revision 19 of this test case created

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 < 50; i +=1)
{
    form.appendChild(array[i]);
}
   
document.body.appendChild(form);
document.body.offsetHeight;
document.body.removeChild(form);
pending…
Document Fragment
var formDiv = document.createDocumentFragment(),
    form = document.createElement('form'),
    array = [
        document.createElement('input'),
        document.createElement('input'),
        document.createElement('input'),
        document.createElement('input')
    ], i;
   
for (i = 0; i < 50; i +=1)
{
    formDiv.appendChild(array[i]);
}
   
form.appendChild(formDiv);
document.body.appendChild(form);
document.body.offsetHeight;
document.body.removeChild(form);
pending…
Normal Append in DOM
var form = document.createElement('form'),
    array = [
        document.createElement('input'),
        document.createElement('input'),
        document.createElement('input'),
        document.createElement('input')
    ], i;
document.body.appendChild(form);    
for (i = 0; i < 50; i +=1)
{
    form.appendChild(array[i]);
}
   

document.body.offsetHeight;
document.body.removeChild(form);
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