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
Comparation between String.replace and handlebars compiled tempaltes
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/handlebars.js/2.0.0/handlebars.min.js"></script>
<script id="tpl" type="template/handlebars">
Hello {{name}}!
</script>
var templateHTML = $('#tpl').html();
var corrected = document.getElementById("tpl").innerHTML;
var data = {name: 'Fer'};
// Handlebars template function
var templateHandlebars = Handlebars.compile(templateHTML);
// Replace based templating
function templateReplace(tmpl, vals) {
var rgxp, repr, noEscapeRgxp;
// default to doing no harm
tmpl = tmpl || '';
vals = vals || {};
// regular expression for matching our placeholders; e.g., #{my-cLaSs_name77}
rgxp = /#\{([^{}]*)}/g;
// regex for text (markup) that should not be escaped; e..g., #{{html_content}}
noEscapeRgxp = /#\{{([^{}]*)}}/g;
// function to making replacements
repr = function (str, match) {
var value = vals[match];
return (typeof value === 'string' || typeof value === 'number') ? htmlEncode(value) : str;
};
// non-escaped text (HTML)
noEscapeRepr = function (str, match) {
var value = vals[match];
return (typeof value === 'string' || typeof value === 'number') ? value : str;
};
return tmpl.replace(rgxp, repr).replace(noEscapeRgxp, noEscapeRepr);
}
Ready to run.
Test | Ops/sec | |
---|---|---|
Replace based template engine |
| ready |
Handlebars template engine |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.