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
Small HTML webapp representing non-trivial Handlebars template. Near real world scenario. It is one small widget representing eshop product comparator. It is completly rendered as Handlebars template and include:
My previous test with Underscore templates show huge performance gain when precompiling templates into JS functions.
Handlebars is not only providing compilation of templates, it also provides some sort of optimization when compiling template function. I want to test this as well, so I prepared compilation results for:
For more details please visit project demo.
<!-- Libraries -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="https://s3.amazonaws.com/github/downloads/wycats/handlebars.js/handlebars-1.0.rc.1.min.js"></script>
<!-- Precompiled templates -->
<script src="http://js.srigi.sk/zandlebars/js/app/templates/templates.js"></script>
<script src="http://js.srigi.sk/zandlebars/js/app/templates/templates.opt1.js"></script>
<script src="http://js.srigi.sk/zandlebars/js/app/templates/templates.opt2.js"></script>
<!-- Render data -->
<script src="http://js.srigi.sk/zandlebars/js/fixtures.js"></script>
<!-- Templates for "noncompiled" test -->
<script type="text/x-handlebars-template" id="comparator-template">
<h2 class="comparator-headline">Compare products</h2>
{{#each products}}
<div class="comparator-item {{comparatorPosition @index}}" comparator-product-id="{{this.id}}">
{{> comparatorItem}}
</div>
{{/each}}
</script>
<script type="text/x-handlebars-template" id="comparator-item-template">
<div class="comparator-product">
<img class="comparator-product-image" src="{{imageUrl}}" />
<h3 class="comparator-product-name">{{name}}</h3>
<dl>
<dt>Sensor</dt>
<dd>{{attributes.sensor}}</dd>
<dt>Lens</dt>
<dd>{{attributes.lens}}</dd>
<dd>Optical zoom: {{attributes.opticalZoom}}×, Digital Zoom: {{attributes.digitalZoom}}×</dd>
<dd>Luminosity: {{attributes.luminosity}}</dd>
<dd>Focal length: {{attributes.focalLength}}</dd>
{{#if attributes.iris}}
<dd>Iris: {{attributes.iris}}</dd>
{{/if}}
{{#if attributes.irisRange}}
<dd>Iris range: {{attributes.irisRange}}</dd>
{{/if}}
<dt>Exposition</dt>
<dd>{{attributes.exposition}}</dd>
<dd>{{attributes.expositionRange}}</dd>
{{#if attributes.whiteBalance}}
<dt>White balance</dt>
<dd>{{attributes.whiteBalance}}</dd>
{{/if}}
<dt>ISO</dt>
<dd>{{attributes.iso}}</dd>
<dt>LCD panel</dt>
<dd>{{attributes.lcdPanel}}, {{attributes.lcdPanelResolution}}</dd>
<dd>{{attributes.lcdPanelFeatures}}</dd>
<dt>Memory cards</dt>
<dd>{{attributes.memoryCards}}</dd>
<dt>File formats</dt>
<dd>{{{explodeText attributes.fileFormats ","}}}</dd>
<dt>File resolutions</dt>
{{#each attributes.fileResolutions}}
<dd>{{@key}}: {{{explodeText this ","}}}</dd>
{{/each}}
<dt>Connectivity</dt>
<dd>{{{explodeText attributes.connectivity ","}}}</dd>
{{#if attributes.other}}
<dt>Other</dt>
<dd>{{attributes.other}}</dd>
{{/if}}
<dt>Powering</dt>
<dd>{{attributes.powering}}</dd>
<dt>Dimensions</dt>
<dd>{{attributes.dimensions}}</dd>
<dt>Weight</dt>
<dd>{{attributes.weight}}</dd>
<dt>Accessories</dt>
<dd>{{{explodeText attributes.accessories ","}}}</dd>
</dl>
</div>
</script>
<script>
var comparatorSource = $('#comparator-template').html();
var comparatorItemSource = $('#comparator-item-template').html();
Handlebars.registerHelper("comparatorPosition", function(index) {
switch (index) {
case 0: return "comparator-item-left span3";
case 1: return "comparator-item-middle span4";
case 2: return "comparator-item-right span3";
}
});
Handlebars.registerHelper("explodeText", function(text, delimiter) {
if ('string' === typeof text) {
return text.split(delimiter).join('<br />');
} else {
return '';
}
});
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
noncompiled |
| ready |
precompiled |
| ready |
precompiled.optimized (--known) |
| ready |
precompiled.optimized (--known --knownOnly) |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.