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
A comparison of the precompilation step for some JavaScript templating engines, when used for multilevel templates:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="http://cdn.kendostatic.com/2011.2.804/js/kendo.all.min.js"></script>
<!--External Template Definitions-->
<script type="text/x-kendo-template" id="kendoUIextTemplate">
<div>
<h1 class='header'><#= data.header #></h1>
<h2 class='header2'><#= data.header2 #></h2>
<h3 class='header3'><#= data.header3 #></h3>
<h4 class='header4'><#= data.header4 #></h4>
<h5 class='header5'><#= data.header5 #></h5>
<h6 class='header6'><#= data.header6 #></h6>
<# for (var ix = 0, l = data.lists.length; ix < l; ix++) {
var listsElem = data.lists[ix];
#>
<h1><#= listsElem.title #></h1>
<ul class='list'>
<# for (var mx = 0, n = listsElem.listitem.length; mx < n; mx++) {
var listitemElem = listsElem.listitem[mx];
#>
<li class='item'><#= listitemElem.i #></li>
<# } #>
</ul>
<# } #>
</div>
</script>
<script>
window.variabledata_tree = {
header: "Header",
header2: "Header2",
header3: "Header3",
header4: "Header4",
header5: "Header5",
header6: "Header6",
lists: [
{
title: "Long list",
listitem: [{i:'1'}, {i:'2'}, {i:'3'}, {i:'4'}, {i:'5'}, {i:'6'}, {i:'7'}, {i:'8'}]
},
{
title: "Short list",
listitem: [{i:'A'}, {i:'B'}, {i:'C'}]
}
]
};
//Resig modified template function (no "with" block)
function tmpl2(str) {
var strFunc =
"var p=[];" +
"p.push('" +
str.replace(/[\r\t\n]/g, " ")
.replace(/'(?=[^#]*#>)/g, "\t")
.split("'").join("\\'")
.split("\t").join("'")
.replace(/<#=(.+?)#>/g, "',$1,'")
.split("<#").join("');")
.split("#>").join("p.push('")
+ "');return p.join('');";
return new Function("data", strFunc);
}
var T2={};
T2.Template = (function(){
var t2c_sub = function(id,tmpls,parent) {
var str = tmpls[id],
indexVar = '_'+id.replace('.','_'),
arrayVar = indexVar+'Arr',
elemVar = indexVar+'Elem',
strFunc = "';for (var "+indexVar+"=0, "+arrayVar+"="+parent+"."+id+"; "+indexVar+"<"+arrayVar+".length; "+indexVar+"++) {var "+elemVar+"="+arrayVar+"["+indexVar+"]; p+='" +
str
.replace(/[\r\t\n]/g, " ")
.replace(/'(?=[^#]*#\})/g, "\t")
.split("'").join("\\'")
.split("\t").join("'")
.replace(/\{=@(.+?)\}/g, function(a,b){ return t2c_sub(b,tmpls,elemVar); })
.replace(/\{=(.+?)\}/g, "'+"+elemVar+".$1+'")
.split("{#").join("';")
.split("#}").join("p+='")
+ "';}p+='";
return strFunc;
};
var exports = {};
exports.precompile = function(tmpls) {
var str = tmpls['$'],
strFunc = "var p='';p+='" +
str
.replace(/[\r\t\n]/g, " ")
.replace(/'(?=[^#]*#\})/g, "\t")
.split("'").join("\\'")
.split("\t").join("'")
.replace(/\{=@(.+?)\}/g, function(a,b){ return t2c_sub(b,tmpls,'data'); })
.replace(/\{=(.+?)\}/g, "'+data.$1+'")
.split("{#").join("';")
.split("#}").join("p+='")
+ "';return p;";
return new Function("data", strFunc);
};
return exports;
})();
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
Resig Micro Templates (No "with" block) |
| ready |
Kendo UI Templates (No "with" block) |
| ready |
Kendo UI Templates (External Temp Def - No "with" block)) |
| ready |
T2 template v5 (Resig+Kendo, w. loop sugar) |
| ready |
T2 template v6 (Resig+Kendo, using JS blocks) |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.