Angular VS Ember VS Backbone VS CanJS VS Knockout (v15)

Revision 15 of this benchmark created on


Description

CanJS using latest and more correct syntax.

Preparation HTML

<script src="https://code.jquery.com/jquery-1.9.1.min.js">
</script>

<!-------- Angular -------->
<div ng-app="ANGAPP" id="angapp" ng-controller="Ctrl">
        <h3>Angular</h3>
        <span ng-repeat="item in items">{{item}}</span>
</div>

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.9/angular.min.js">
</script>

<script>
angular.module('ANGAPP', [])
        .controller('Ctrl', function($scope) {
        $scope.items = [];
    $scope.clear = function(){$scope.items = [];};
    $scope.push = function(item){ $scope.items.push(item);};
        window.ANG = {
      $scope : $scope
        };
        });
</script>
<!-------- End Angular -------->


<!-------- CanJS -------->
<script src="http://canjs.com/release/latest/can.jquery.js"></script>
<div id="canjsmustacheapp"></div>

<script id='canjsMustacheTemplate' type='text/mustache'>
  <h3>CanJS (Mustache):</h3>
  <span class="canjs-items">{{#each items}}{{.}}{{/each}}</span>
</script>

<script>
var canjsList1 = new can.List();
var canjsControl = can.Control.extend({
  init: function(el, options) {
    this.element.html(can.view(this.options.template, { items: this.options.items }));
  },
  push: function(i) {
    this.options.items.push(i);
  },
  clear: function() {
    this.options.items.replace([]);
  }
});

window.CanJS = new canjsControl('#canjsmustacheapp', {
    template: 'canjsMustacheTemplate',
    items: canjsList1
});
</script>
<!-------- End CanJS -------->


<!-------- Backbone-------->
<div id="backboneapp">
  <h3>Backbone</h3>
  <span class="backbone-items"></span>
</div>

<script src="https://underscorejs.org/underscore.js"></script>
<script src="https://backbonejs.org/backbone.js"></script>
<script>
// Backbone.js
var backboneView = Backbone.View.extend({
  push: function(i) {
    this.$el.append(i);
  },
  clear: function() {
    this.$el.html('');
  }
});

window.BB = new backboneView({el: "#backboneapp .backbone-items"});
</script>
<!-------- End Backbone -------->

<!-------- Knockout -------->

<h3>Knockout</h3>
<span data-bind='foreach: items'><span data-bind="text: $data"></span></span>

<script src="https://knockoutjs.com/downloads/knockout-2.3.0.js"></script>
<script>
// Knockout.js
window.KO = {
    items: ko.observableArray([]),
    clear: function() {
       this.items([]);
    },
    push: function(item) {
        this.items.push(item);
    }
}
ko.applyBindings(KO);
</script>
<!-------- End Knockout -------->


<!-------- Ember-------->
<div id="emapp">
  <h3>Ember:</h3>
  <script type="text/x-handlebars">
    <span>
      {{#each EMapp.data}}<span>{{this}}</span>{{/each}}
    </span>
  </script>
</div>

<script src="http://builds.handlebarsjs.com.s3.amazonaws.com/handlebars-v1.2.1.js"></script>
<script src="http://builds.emberjs.com/tags/v1.3.1/ember.prod.js"></script>

<script>
  EMapp = Ember.Application.create({
    rootElement: $('#emapp')
  });
  EMapp.data = Ember.A();
  
  EMclear = function () {
    EMapp.get('data').clear();
  };
  EMreset = function () {
    EMapp.set('data', Ember.A());
  };
  EMpush = function (data) {
    EMapp.get('data').pushObject(data);
  };
</script>
<!-------- End Ember -------->

Test runner

Ready to run.

Testing in
TestOps/sec
Angular
ANG.$scope.clear();
for (var i = 0; i < 50; i++) {
  ANG.$scope.push(i);
  ANG.$scope.$apply();
}
ready
CanJS
can.batch.start();
CanJS.clear();
for (var i = 0; i < 50; i++) {
  CanJS.push(i);
}
can.batch.stop();
ready
Backbone
BB.clear();
for (var i = 0; i < 50; i++) {
  BB.push(i);
}
ready
Knockout
KO.clear();
for (var i = 0; i < 50; i++) {
  KO.push(i);
}
ready
Ember
EMclear();
for (var i = 0; i < 50; i++) {
  EMpush(i);
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.