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
First of all I apologize for my "perfect" English.
This benchmark trying to measure three types of JavaScript templates usage:
#document-fragment
DOM element
All three cases demonstrate the behavior of templates in the real world applicance.
Actualy we interested in one behaviour - rendering template to string with the further application, but we include some reactive libs that initialy get binded to the dom.
As far those libraries included:
musatche.js (src) - 0.7.2 - String-based
Hogan.js (src) - 2.0.0 - String-based
Handlebars.js (src) - 1.0.0 - String-based - Compile option data: false
applied *
Ractive.js (src) - 0.3.6 - Bindable - Compile option twoway: false
applied **
Bindable type actualy behaives like Reactive in terms of Two-Way data binding
* From Handlebars.js documentstion's optimizations
section:
Implementations that do not use @data variables can improve performance of iteration centric templates by specifying {data: false} in the compiler options.
** From Ract.js documentation's Initialisation options
section:
twoway Boolean
Defaults to true. Whether or not two-way data binding is enabled (see Two‐way binding).
<!-- Include needed scripts -->
<script src="http://cdn.ractivejs.org/latest/ractive.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.0.0/handlebars.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mustache.js/0.7.2/mustache.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/hogan.js/2.0.0/hogan.js"></script>
<pre id="container">
</pre>
// Populationg template data
var data = {
title: 'Seo Optimised Article Title',
article: {
title: 'Article Title',
body: 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ut laboriosam voluptate iure dolor fugit quod nihil accusantium nemo quas eligendi?'
}
};
// Populating template strings
var templates = {};
templates.mustache = '<article><div class="row eight"><h1>{{{article.title}}}</h1><p>{{{article.body}}}</p></div></article>';
templates.ractive = '<article><div class="row eight"><h1>{{article.title}}</h1><p>{{article.body}}</p></div></article>';
// Iterator - monkey patching Ractive #set behaviour
var i = 0;
// Chaching container dom elements
var $dom = document.getElementById('container');
var $fragment = document.createDocumentFragment();
// Pre-compiling templates, creating doc. fragments
// mustache
var mustache = Mustache.compile(templates.mustache);
// Hogan.js
var hogan = Hogan.compile(templates.mustache);
// Handlebar.js
var handlebars = Handlebars.compile(templates.mustache);
// Handlebars with `data: false` optimisation on loops
var handlebars_optimised = Handlebars.compile(templates.mustache, { data: false });
// Ractive, initialy works with dom
var ractive_fragment = new Ractive({
el: $fragment,
template: templates.ractive,
data: data,
twoway: false
});
var ractive_dom = new Ractive({
el: $fragment,
template: templates.ractive,
data: data,
twoway: false
});
i = 0;
Ready to run.
Test | Ops/sec | |
---|---|---|
mustache.js |
| ready |
mustache.js (FRAGMENT) |
| ready |
mustache.js (DOM) |
| ready |
Hogan.js |
| ready |
Hogan.js (FRAGMENT) |
| ready |
Hogan.js (DOM) |
| ready |
Handlebars.js |
| ready |
Handlebars.js (FRAGMENT) |
| ready |
Handlebars.js (DOM) |
| ready |
Handlebars.js - optimised |
| ready |
Handlebars.js - optimised (FRAGMENT) |
| ready |
Handlebars.js - optimised (DOM) |
| ready |
Reactive.js - singular (FRAGMENT) |
| ready |
Reactive.js - comulative (FRAGMENT) |
| ready |
Reactive.js - singular (DOM) |
| ready |
Reactive.js - comulative (DOM) |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.