dom append or dom-fragment append
JavaScript performance comparison
Info
Testing/profiling the code patterns from the Script Junkie article "(pre)Maturely Optimize Your JavaScript"
http://msdn.microsoft.com/en-us/scriptjunkie/gg622887.aspx
Snippet comparison #7
Preparation code
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
var list_count = 0,
the_list = [];
for (var i = 0; i < 75; i++) {
the_list[i] = Math.random();
}
function makeUL_1(list) {
$("<ul></ul>").attr({
"id": "my_list" + list_count
}).appendTo("body");
for (var i = 0; i < list.length; i++) {
$("<li></li>").text(list[i]).appendTo("#my_list" + list_count);
}
$("#my_list" + list_count).hide();
list_count++;
}
function makeUL_2(list) {
var $ul = $("<ul></ul>").attr({
"id": "my_list" + list_count
});
for (var i = 0; i < list.length; i++) {
$("<li></li>").text(list[i]).appendTo($ul);
}
$ul.appendTo("body");
$ul.hide();
list_count++;
}
</script>
Preparation code output
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
dom append |
|
pending… |
dom-fragment append |
|
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:
- Revision 1: published by Kyle Simpson
- Revision 2: published by Maher Salam
0 comments