Fastest way to create lists

JavaScript performance comparison

Test case created by NJ Manoj

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<ul id="listview1">
</ul>
<ul id="listview2">
</ul>
<ul id="listview3">
</ul>
<script>
Benchmark.prototype.setup = function() {
    var ul1 = document.getElementById("listview1");
    ul1.innerHTML = "";
    var liList = [];
   
    var ul2 = document.getElementById("listview1");
    ul2.innerHTML = "";
    var liHtml = "";
   
    var ul3 = $("#listview2");
    ul3.html("");
};

Benchmark.prototype.teardown = function() {
    ul1.innerHTML = liList.join("");
   
    ul2.innerHTML = liHtml;
};
</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
innerHTML - array
liList.push("<li>List Item</li>");
pending…
innerHTML - string
liHtml += "<li>List Item</li>";
pending…
jQuery appendTo
$("<li/>", {
  text: "List Item"
}).appendTo(ul3);
pending…

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

Compare results of other browsers

0 comments

Add a comment