appendChild vs. DocumentFragment vs. innerHTML (v42)

Revision 42 of this benchmark created on


Description

Comparing 3 different ways to dynamically insert new elements into the DOM tree.

Preparation HTML

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

Test runner

Ready to run.

Testing in
TestOps/sec
append string
$("#test1").append($("<p>").text("aaaaaa"));
$("#test1").empty();
ready
append element
var p = $("#test1");
p.append($("<p>").text("aaaaaa"));
$("#test1").empty();
ready
element append string
var div= $("#test1");
var p= $("p").text("aaaaaaa").eq(0);
div.append(p);

$("#test1").empty();
ready
element append element
var div= $("#test1");
var p= $("p").filter(":first").text("aaaaaaa");
div.append(p);

$("#test1").empty();
ready

Revisions

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