append vs. innerHTML vs. fragment

JavaScript performance comparison

Revision 16 of this test case created

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<script>
Benchmark.prototype.setup = function() {
    var html = "<div><ul><li>df</li><li>fdf</li></ul></div>";
    var d = document.createElement('div');
    document.body.appendChild(d);
};

Benchmark.prototype.teardown = function() {
    document.body.removeChild(d);
};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
jQuery append
$(d).append(html);
pending…
innerHTML
d.innerHTML = html;
pending…
fragment
var f = document.createDocumentFragment();
f.innerHTML = html;
d.appendChild(f);
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