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
This is a simple rendering speed test between the most popular libraries/frameworks. I've added the 3 templating languages from CanJS 2.1-pre
<!-- Jquery -->
<script src="https://cdn.jsdelivr.net/jquery/2.1.0/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/angularjs/1.2.15/angular.min.js"></script>
<script src="https://cdn.jsdelivr.net/knockout/3.1.0/knockout.js"></script>
<script src="https://cdn.jsdelivr.net/handlebarsjs/1.3.0/handlebars.js"></script>
<script src="https://cdn.jsdelivr.net/emberjs/1.5.0/ember.min.js"></script>
<script src="https://cdn.jsdelivr.net/react/0.10.0/react-with-addons.js"></script>
<script src="https://cdn.jsdelivr.net/mithril/0.1.9/mithril.min.js"></script>
<!-- CanJS has its own $.fn.scope plugin which we aren't using here so restore Angular's -->
<script>
var ANGScope = $.fn.scope;
</script>
<!-- 2.1 Pre release -->
<script src="http://pixelplicity.com/can.jquery.js"></script>
<script src="http://pixelplicity.com/can.stache.js"></script>
<script src="http://pixelplicity.com/can.ejs.js"></script>
<script>
$.fn.scope = ANGScope;
</script>
<!-- Angular -->
<div ng-app>
Angular:
<span ng-controller="Ctrl" id="angList"><span ng-repeat="item in data">{{item}}</span></span>
</div>
<!-- Knockout -->
<div id="koapp">
Knockout:
<span data-bind="foreach: data"><span data-bind="text: $data"></span></span>
</div>
<!-- Ember -->
<div id="emapp"></div>
<script type="text/x-handlebars">
Ember:
<span>
{{#each EMapp.data}}<span>{{this}}</span>{{/each}}
</span>
</script>
<!-- React -->
<div id="react">
React: <span id="reactMountNode"></span>
</div>
<!-- Mithril -->
<div id="mithrilapp">
Mithril: <span id="mithrilMountNode"></span>
</div>
<!-- CanJS -->
<div id="canejsapp"></div>
<div id="canmustacheapp"></div>
<div id="canstacheapp"></div>
<script id="canejs" type="text/ejs">
CanJS (ejs):
<span>
<% data.forEach(function(item){ %>
<span><%= item %></span>
<% }) %>
</span>
</script>
<script id="canmustache" type="text/mustache">
CanJS (mustache):
<span>
{{#data}}<span>{{.}}</span>{{/data}}
</span>
</script>
<script id="canstache" type="text/stache">
CanJS (stache):
<span>
{{#data}}<span>{{.}}</span>{{/data}}
</span>
</script>
<script>
var Ctrl = function($scope){ $scope.data = []; };
var KOData = ko.observableArray();
var KOviewmodel = {data: KOData};
var ENV = {EXTEND_PROTOTYPES: false};
var ReactComponent = React.createClass({displayName: 'PerfTest',
getInitialState: function() {
return { data: [] };
},
render: function() {
var res = [];
for(var i = 0; i < this.state.data.length; i++) {
res.push(React.DOM.span({ key: 'test' + i }, this.state.data[i]));
}
return React.DOM.span(null, res);
}
});
var MithrilData = new Array();
var mithapp = {
controller: function() {
this.data = MithrilData;
},
view: function(ctrl) {
return m("span", [ctrl.data.map(function(datum) { return m('span', datum); })]);
}
}
$(document).ready(function() {
angular.element(document).ready(function() {
var ang_scope = $('#angList').scope();
window.ANGclear = function(){
ang_scope.data.splice(0, ang_scope.data.length);
ang_scope.$digest();
};
window.ANGpush = function(data){
ang_scope.data.push(data + ang_scope.data.length);
ang_scope.$digest();
};
});
ko.applyBindings(KOviewmodel, document.getElementById('koapp'));
window.KOclear = function (){
KOData.splice(0, KOData().length);
};
window.KOpush = function (data){
KOData.push(data);
};
EMapp = Ember.Application.create({
rootElement: '#emapp'
});
EMapp.data = Ember.A();
window.EMclear = function () {
EMapp.data.clear();
};
window.EMpush = function (data) {
EMapp.data.pushObject(data);
};
var reactComp = ReactComponent();
React.renderComponent(reactComp, $('#reactMountNode')[0]);
window.RClear = function() {
reactComp.setState({data: []})
};
window.RPush = function(data) {
var stateData = reactComp.state.data;
stateData.push(data);
reactComp.setState({data: stateData});
}
m.module(document.getElementById("mithrilMountNode"), mithapp);
window.Mclear = function() {
m.startComputation();
MithrilData.splice(0);
m.endComputation();
};
window.Mpush = function(data) {
m.startComputation();
MithrilData.push(data);
m.endComputation();
}
var canData = {
'ejs': new can.List([]),
'mustache': new can.List([]),
'stache': new can.List([])
};
var canRenderer = {
'ejs': can.view('canejs'),
'mustache': can.view('canmustache'),
'stache': can.view('canstache')
};
can.each(['ejs', 'mustache', 'stache'], function(type) {
$('#can' + type + 'app').append(canRenderer[type]({data: canData[type]}));
});
window.CANclear = function(type){
canData[type].splice(0, canData[type].length);
};
window.CANpush = function(type, data){
canData[type].push(data);
};
});
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
Angular 10 |
| ready |
Knockout 10 |
| ready |
Ember 10 |
| ready |
Angular 100 |
| ready |
Knockout 100 |
| ready |
Ember 100 |
| ready |
React 10 |
| ready |
React 100 |
| ready |
Mithril 10 |
| ready |
Mithril 100 |
| ready |
CanJS (EJS) 10 |
| ready |
CanJS (EJS) 100 |
| ready |
CanJS (Mustache) 10 |
| ready |
CanJS (Mustache) 100 |
| ready |
CanJS (Stache) 10 |
| ready |
CanJS (Stache) 100 |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.