Dom Manipulation - Js Templating vs programmatic jQuery
JavaScript performance comparison
Info
What is faster, generating elements on the fly using jQuery appends and generator or using javascript templates.
Preparation code
<script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.1.7/underscore-min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<!-- The Javascript template - using underscore.js -->
<script type="text/template" id="combo_template">
<select>
<% _.each(values, function(value) { %>
<option><%= value %></option>
<% }); %>
</select >
</script>
<div id="testcontainer" style="display: none;"></div>
<script>
$("#testcontainer").empty();
var values = ["SOMETHING", "THOMAS","THOMAS","THOMAS","THOMAS","THOMAS","THOMAS","THOMAS","THOMAS","THOMAS","THOMAS","THOMAS","THOMAS","THOMAS","THOMAS","THOMAS","THOMAS","THOMAS","THOMAS","THOMAS","THOMAS","THOMAS","THOMAS"];
</script>
Preparation code output
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
Javascript Templates |
|
pending… |
jQuery Append |
|
pending… |
Stringed Dom |
|
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 Thomas Davis
- Revision 2: published
- Revision 4: published by DongwooKim
- Revision 5: published
- Revision 6: published by built2fall
- Revision 7: published
- Revision 8: published
- Revision 9: published
- Revision 10: published
- Revision 11: published
- Revision 12: published
- Revision 13: published
- Revision 14: published
- Revision 15: published
- Revision 16: published by Dave
- Revision 17: published
- Revision 18: published
- Revision 19: published
- Revision 20: published
- Revision 21: published
- Revision 24: published
- Revision 25: published
- Revision 26: published
- Revision 27: published
- Revision 28: published
- Revision 29: published
- Revision 30: published by darren
- Revision 31: published
6 comments
lol at IE speeds
I just added IE6 (for giggles), Opera, some iPads, iPhones, Camino and the latest Chrome Canary build. In other news... if you need advice on how to party it up on a Friday night just ask away.
I need friday night party ideas for a house full of dudes and no chance of women.
May I humbly suggest you get everyone a suite of outdated browsers and have them start posting test results on this particular Dom Manipulation? Slowest one wins. Then get everyone a bunch of the latest nightlies, fastest one wins.
Or just go where the women are. I find that does wonders for one's chances.
Checkout the revisions for some other cool methods, I really like revision 6
This is a very interesting test suite, I've been researching using Java script templates this week and seeing that they actually work a bit faster then using jQuery's Append is a plus.