createDocumentFragment vs appendChild on non-appended element

JavaScript performance comparison

Revision 15 of this test case created

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<div id="testDiv1">

</div>

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 array = ["one","two","three","four","five"], 
i,
testDiv = $("#testDiv1");
   
var ul = $("<ul>");
for (i = 0; i < 5; i +=1)
{
    var li = $("<li>").text(array[i]);
    ul.append(li);
    console.log(ul.length)
}
testDiv.append(ul).hide();
pending…
Document Fragment
var frag = document.createDocumentFragment(),
    array = [
        "one","two","three","four","five"
    ], i;
   
var ul = document.createElement('ul');
for (i = 0; i < 5; i +=1)
{
    var li = document.createElement('li');
    li.innerHTML = array[i];
    ul.appendChild(li);
    console.log(ul.length)
}
frag.appendChild(ul);
document.getElementById("testDiv1").appendChild(frag);
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