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
<script>
var template = '<tr><td>{title}</td><td>{type}</td><td><a href="tags/{tag}">{tag}</a></td><td>{created_at}</td></tr>';
var data = {
title: 'title',
type: 'type',
tag: 'tag',
created_at: 'created_at'
};
function processTemplate1(template) {
if (typeof template === 'object') {
for (var i in template)
template[i] = processTemplate1(template[i]);
}
else if (typeof template === 'string') {
template = template.replace(/[\n'\\]/g, '\\$&');
template = template.replace(/\{(\w*)\}/g, function(str, key) {
return "'+d['" + key + "']+'";
});
return new Function("d", "return '" + template + "'");
}
return template;
}
function processTemplate2(template) {
if (typeof template === 'object') {
for (var i in template)
template[i] = processTemplate2(template[i]);
}
else if (typeof template === 'string') {
template = template.replace(/[\n'\\]/g, '\\$&');
template = template.replace(/\{(\w*)\}/g, function(str, key) {
return "'+d." + key + "+'";
});
return new Function("d", "return '" + template + "'");
}
return template;
}
var template1 = processTemplate1(template);
var template2 = processTemplate2(template);
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
Concatenation |
| ready |
Template1 |
| ready |
Template2 |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.