performance comparison of jQuery Template vs underscore vs string append vs mustache vs handlebars vs icanhaz vs milk vs swig for table
JavaScript performance comparison
Info
To test performance of jQuery template for outputting 100 rows each with 10 columns where the columns have fields that can trigger events.
Preparation code
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js">
</script>
<script src="http://ajax.microsoft.com/ajax/jquery.templates/beta1/jquery.tmpl.js">
</script>
<script src="http://documentcloud.github.com/underscore/underscore-min.js">
</script>
<script src="http://github.com/janl/mustache.js/raw/master/mustache.js">
</script>
<script src="https://raw.github.com/BorisMoore/jsrender/master/jsrender.js">
</script>
<script src="https://github.com/andyet/ICanHaz.js/raw/master/ICanHaz.min.js">
</script>
<script src="http://github.com/pvande/Milk/raw/master/dist/v1.2.0/milk.js">
</script>
<script src="http://dl.dropbox.com/u/426176/js/swig/swig.js">
</script>
<script src="http://cloud.github.com/downloads/wycats/handlebars.js/handlebars-1.0.0.beta.6.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
$('body').delegate('#table .edit a, #table .select a', 'click', function() {
var $td = $(this).closest('td');
$td.find('input, select').show();
$td.find('a').hide();
});
$('body').delegate('#table .edit .cancel, $table .select .cancel', 'click', function() {
var $td = $(this).closest('td');
$td.find('input, select').hide();
$td.find('a').show();
});
});
</script>
<script type="text/x-jquery-tmpl" id="tmplRow">
< tr > < td > < input type = "checkbox"
value = "${id}" / > < /td>
<td>${firstName} ${lastName}</td > < td class = "edit" > < a > Edit < /a>
<input style="display:none;" type="hidden" value="Blah" / > < input class = "cancel"
type = "button"
value = "cancel" / > < /td>
<td class="select">
<a>Select</a > < select style = "display:none;" > < option > 0 < /option>
<option>1</option > < option > 2 < /option>
<option>3</option > < option > 4 < /option>
<option>5</option > < option > 6 < /option>
<option>7</option > < option > 8 < /option>
<option>9</option > < option > 10 < /option>
</select > < input class = "cancel"
type = "button"
value = "cancel" / > < /td>
<td>More string</td > < td > More string < /td>
<td>More string</td > < td > More string < /td>
<td>More string</td > < td > More string < /td>
</tr >
</script>
<script type="text/x-handlebars-template" id="handlebarsTmpl">
{{#each rows}}
{{#with this}}
< tr > < td > < input type = "checkbox"
value = "{{id}}" / > < /td>
<td>{{firstName}} {{lastName}}</td > < td class = "edit" > < a > Edit < /a>
<input style="display:none;" type="hidden" value="Blah" / > < input class = "cancel"
type = "button"
value = "cancel" / > < /td>
<td class="select">
<a>Select</a > < select style = "display:none;" > < option > 0 < /option>
<option>1</option > < option > 2 < /option>
<option>3</option > < option > 4 < /option>
<option>5</option > < option > 6 < /option>
<option>7</option > < option > 8 < /option>
<option>9</option > < option > 10 < /option>
</select > < input class = "cancel"
type = "button"
value = "cancel" / > < /td>
<td>More string</td > < td > More string < /td>
<td>More string</td > < td > More string < /td>
<td>More string</td > < td > More string < /td>
</tr >
{{/with}}
{{/each}}
</script>
<script type="text/html" id="icanhazTmpl">
{{#rows}}
< tr > < td > < input type = "checkbox"
value = "{{id}}" / > < /td>
<td>{{firstName}} {{lastName}}</td > < td class = "edit" > < a > Edit < /a>
<input style="display:none;" type="hidden" value="Blah" / > < input class = "cancel"
type = "button"
value = "cancel" / > < /td>
<td class="select">
<a>Select</a > < select style = "display:none;" > < option > 0 < /option>
<option>1</option > < option > 2 < /option>
<option>3</option > < option > 4 < /option>
<option>5</option > < option > 6 < /option>
<option>7</option > < option > 8 < /option>
<option>9</option > < option > 10 < /option>
</select > < input class = "cancel"
type = "button"
value = "cancel" / > < /td>
<td>More string</td > < td > More string < /td>
<td>More string</td > < td > More string < /td>
<td>More string</td > < td > More string < /td>
</tr >
{{/rows}}
</script>
<script type="text/template" id="swigTmpl">
{% for row in rows %}
<tr>
<td><input type="checkbox" value="{{ row.id }}" />< /td>
<td>{{ row.firstName }} {{ row.lastName }}</td>
<td class="edit">
<a>Edit</a>
<input style="display:none;" type="hidden" value="Blah" />
<input class="cancel" type="button" value="cancel" />
</td>
<td class="select">
<a>Select</a >
<select style="display:none;">
<option>0</option>
<option>1</option><option>2</option>
<option>3</option><option>4</option>
<option>5</option><option>6</option>
<option>7</option><option>8</option>
<option>9</option><option>10</option>
</select >
<input class="cancel" type="button" value="cancel" />
</td>
<td>More string</td><td>More string</td>
<td>More string</td><td>More string</td>
<td>More string</td><td>More string</td>
</tr>
{% endfor %}
</script>
<script>
var data = [];
for (var i = 0; i < 100; i++) {
var row = {
id: i,
firstName: 'john',
lastName: 'doe'
};
data.push(row);
}
$.template("savedTmpl", document.getElementById("tmplRow").innerHTML);
var underscoreTmpl = "\
<%for(var i=0;i<rows.length;i++){%>\
<%var row=rows[i];%> \
<tr> \
<td> <input type = 'checkbox' value = '<%= row.id%>' /> </td>\
<td><%= row.firstname%> <%= row.lastname%></td> \
<td class = 'edit'> \
<a> Edit </a>\
<input style='display:none;' type='hidden' value='Blah' /> \
<input class = 'cancel' type = 'button' value = 'cancel' /> \
</td>\
<td class='select'>\
<a>Select</a> \
<select style = 'display:none;'> \
<option>0</option>\
<option>1</option> \
<option>2</option>\
<option>3</option> \
<option>4</option>\
<option>5</option> \
<option>6</option>\
<option>7</option> \
<option>8</option>\
<option>9</option> \
<option>10</option>\
</select> \
<input class = 'cancel' type = 'button' value = 'cancel' /> \
</td>\
<td>More string</td> \
<td>More string</td>\
<td>More string</td> \
<td>More string</td>\
<td>More string</td> \
<td>More string</td>\
</tr ><%}%>";
var mustacheTmpl = "\
{{#rows}}\
<tr> \
<td> <input type = 'checkbox' value = '{{id}}' /> </td>\
<td>{{firstname}} {{lastname}}</td> \
<td class = 'edit'> \
<a> Edit </a>\
<input style='display:none;' type='hidden' value='Blah' /> \
<input class = 'cancel' type = 'button' value = 'cancel' /> \
</td>\
<td class='select'>\
<a>Select</a> \
<select style = 'display:none;'> \
<option>0</option>\
<option>1</option> \
<option>2</option>\
<option>3</option> \
<option>4</option>\
<option>5</option> \
<option>6</option>\
<option>7</option> \
<option>8</option>\
<option>9</option> \
<option>10</option>\
</select> \
<input class = 'cancel' type = 'button' value = 'cancel' /> \
</td>\
<td>More string</td> \
<td>More string</td>\
<td>More string</td> \
<td>More string</td>\
<td>More string</td> \
<td>More string</td>\
</tr >{{/rows}}"
var milkTmpl = "\
{{#rows}}\
<tr> \
<td> <input type = 'checkbox' value = '{{id}}' /> </td>\
<td>{{firstname}} {{lastname}}</td> \
<td class = 'edit'> \
<a> Edit </a>\
<input style='display:none;' type='hidden' value='Blah' /> \
<input class = 'cancel' type = 'button' value = 'cancel' /> \
</td>\
<td class='select'>\
<a>Select</a> \
<select style = 'display:none;'> \
<option>0</option>\
<option>1</option> \
<option>2</option>\
<option>3</option> \
<option>4</option>\
<option>5</option> \
<option>6</option>\
<option>7</option> \
<option>8</option>\
<option>9</option> \
<option>10</option>\
</select> \
<input class = 'cancel' type = 'button' value = 'cancel' /> \
</td>\
<td>More string</td> \
<td>More string</td>\
<td>More string</td> \
<td>More string</td>\
<td>More string</td> \
<td>More string</td>\
</tr >{{/rows}}"
var jsRenderTmpl = "\
<tr> \
<td> <input type = 'checkbox' value = '{{=id}}' /> </td>\
<td>{{=firstname}} {{=lastname}}</td> \
<td class = 'edit'> \
<a> Edit </a>\
<input style='display:none;' type='hidden' value='Blah' /> \
<input class = 'cancel' type = 'button' value = 'cancel' /> \
</td>\
<td class='select'>\
<a>Select</a> \
<select style = 'display:none;'> \
<option>0</option>\
<option>1</option> \
<option>2</option>\
<option>3</option> \
<option>4</option>\
<option>5</option> \
<option>6</option>\
<option>7</option> \
<option>8</option>\
<option>9</option> \
<option>10</option>\
</select> \
<input class = 'cancel' type = 'button' value = 'cancel' /> \
</td>\
<td>More string</td> \
<td>More string</td>\
<td>More string</td> \
<td>More string</td>\
<td>More string</td> \
<td>More string</td>\
</tr >";
var handlebarsTmpl = Handlebars.compile($("#handlebarsTmpl").html());
swig.init({
autoescape: false,
cache: true,
filters: {}
});
var swigTmpl = swig.compile($("#swigTmpl").html());
</script>
Preparation code output
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
jQuery templates |
|
pending… |
Precompiled jQuery template |
|
pending… |
Underscore.js |
|
pending… |
mustache js |
|
pending… |
jsrender |
|
pending… |
ICanHaz.js |
|
pending… |
Handlebars.js |
|
pending… |
Milk |
|
pending… |
swig |
|
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 Chi Chan
- Revision 5: published by Chi Chan
- Revision 6: published by Sharath Satish
- Revision 7: published
- Revision 8: published by Anil K
- Revision 9: published by Kevin Mee
- Revision 10: published
- Revision 11: published and last updated
- Revision 12: published by Harry Brundage
- Revision 13: published
- Revision 15: published by Bryan Chow
- Revision 16: published
- Revision 17: published
- Revision 18: published
- Revision 19: published
- Revision 20: published
- Revision 21: published by Bharath
- Revision 23: published by Sammy
- Revision 25: published
- Revision 30: published
- Revision 31: published
- Revision 32: published
- Revision 33: published
- Revision 35: published
- Revision 36: published
- Revision 37: published
- Revision 38: published
- Revision 39: published by andy matthews
- Revision 40: published
- Revision 41: published
- Revision 42: published
- Revision 43: published
- Revision 45: published by Dayakar Muluka
- Revision 46: published
- Revision 47: published
- Revision 48: published
- Revision 49: published
- Revision 50: published by Mauricio Wolff
- Revision 51: published by Mauricio Wolff
- Revision 52: published by Larry Davis
- Revision 53: published by Nguyen Trang Hong Bao
- Revision 61: published by Nguyen Trang Hong Bao
- Revision 62: published by Nguyen Trang Hong Bao
- Revision 63: published by Nguyen Trang Hong Bao
- Revision 70: published by Nguyen Trang Hong Bao
- Revision 71: published by Nguyen Trang Hong Bao
- Revision 72: published by Nguyen Trang Hong Bao
- Revision 74: published by atma
- Revision 76: published
- Revision 77: published
- Revision 79: published
- Revision 80: published
- Revision 81: published
- Revision 82: published
- Revision 83: published
- Revision 84: published
- Revision 85: published
- Revision 86: published
- Revision 87: published
- Revision 90: published by Vlad
- Revision 91: published
- Revision 93: published by Leonardo
- Revision 94: published by Leonardo
- Revision 95: published by pp
- Revision 96: published
- Revision 97: published
- Revision 98: published
- Revision 99: published by Leo Sanchez
- Revision 100: published by George Reith
0 comments