jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
To test performance of jQuery template for outputting 100 rows each with 10 columns where the columns have fields that can trigger events.
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js">
</script>
<script src="http://github.com/jquery/jquery-tmpl/raw/master/jquery.tmpl.js">
</script>
<script src="http://documentcloud.github.com/underscore/underscore.js">
</script>
<script src="http://github.com/mhevery/mustache.js/raw/dot-notation/mustache.js">
</script>
<script src="http://github.com/pvande/Milk/raw/master/dist/v1.2.0/milk.js">
</script>
<script src="//raw.github.com/Shopify/batman/master/lib/dist/batman.min.js"></script>
<script type="text/javascript">
(function(a){"use strict";var b=function(a,c){var d=/[^\w\-\.:]/.test(a)?new Function(b.arg+",tmpl","var _e=tmpl.encode"+b.helper+",_s='"+a.replace(b.regexp,b.func)+"';return _s;"):b.cache[a]=b.cache[a]||b(b.load(a));return c?d(c,b):function(a){return d(a,b)}};b.cache={},b.load=function(a){return document.getElementById(a).innerHTML},b.regexp=/([\s'\\])(?![^%]*%\})|(?:\{%(=|#)([\s\S]+?)%\})|(\{%)|(%\})/g,b.func=function(a,b,c,d,e,f){if(b)return{"\n":"\\n","\r":"\\r","\t":"\\t"," ":" "}[a]||"\\"+a;if(c)return c==="="?"'+_e("+d+")+'":"'+("+d+"||'')+'";if(e)return"';";if(f)return"_s+='"},b.encReg=/[<>&"'\x00]/g,b.encMap={"<":"<",">":">","&":"&",'"':""","'":"'"},b.encode=function(a){return String(a||"").replace(b.encReg,function(a){return b.encMap[a]||""})},b.arg="o",b.helper=",print=function(s,e){_s+=e&&(s||'')||_e(s);},include=function(s,d){_s+=tmpl(s,d);}",typeof define=="function"&&define.amd?define(function(){return b}):a.tmpl=b})(this);
$(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>
<table id="batman_template">
<tr data-foreach-person="data">
<td><input type="checkbox" data-bind="person.id"/></td>
<td data-bind="person.firstName | append ' ' | append person.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>
</table>
<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 tmplTemplate = "{%for(var i=0;i<o.length;i++){%}<tr><td><input type='checkbox' value='{%= o[i].id%}'/></td><td>{%= o[i].firstname%} {%= o[i].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 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}}"
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
jQuery templates |
| ready |
string padding method |
| ready |
Precompiled jQuery template |
| ready |
Underscore.js |
| ready |
mustache js |
| ready |
mustache Milk |
| ready |
Javascript Templates |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.