Backbone vs Angular vs Ember vs Knockout

JavaScript performance comparison

Revision 29 of this test case created

Preparation code

<script src="//code.jquery.com/jquery-1.9.1.min.js">
</script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.9/angular.min.js">
</script>

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

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



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

<!-- Knockout -->

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

<script>
// Angular
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>
<script src="//builds.emberjs.com/handlebars-1.0.0-rc.4.js"></script>
<script src="//builds.emberjs.com/tags/v1.3.1/ember.prod.js"></script>
<script>
//Ember
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>

<script src="//underscorejs.org/underscore.js"></script>
<script src="//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>
<script src="//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);

console.log(window.KO);

</script>

Preparation code output

Ember:

Angular

{{item}}

Backbone

Knockout

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Backbone
BB.clear();
for (var i = 0; i < 50; i++) {
  BB.push(i);
}
pending…
Angular
ANG.$scope.clear();
for (var i = 0; i < 50; i++) {
  ANG.$scope.push(i);
}
ANG.$scope.$apply();
pending…
Ember
EMclear();
for (var i = 0; i < 50; i++) {
  EMpush(i);
}
pending…
Knockout
KO.clear();
for (var i = 0; i < 50; i++) {
  KO.push(i);
}
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment