Fastest way to create lists
JavaScript performance comparison
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.
| Test | Ops/sec | |
|---|---|---|
innerHTML - array |
|
pending… |
innerHTML - string |
|
pending… |
jQuery appendTo |
|
pending… |
You can edit these tests or add even more tests to this page by appending /edit to the URL.
0 comments