Angular VS Knockout VS Ember vs CanJS

JavaScript performance comparison

Revision 117 of this test case created by Sebastian

Preparation code

<!-- Jquery -->
<script src="https://code.jquery.com/jquery-1.9.1.min.js">
</script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.1.3/angular.min.js">
</script>
<script src="http://knockoutjs.com/downloads/knockout-2.2.1.js">
</script>
<script src="https://raw.github.com/wycats/handlebars.js/1.0.0-rc.3/dist/handlebars.js"></script>
<script src="https://raw.github.com/emberjs/ember.js/release-builds/ember-1.0.0-rc.2.js">
</script>
<script src="http://canjs.us/release/1.1.5/can.jquery.js"></script>

<!-- CanJS -->
<div id="canapp">
	<h3>Can</h3>	
</div>
<script type="text/ejs" id="canEJS">
	<% list(items, function(item) { %>
	  <span><%= item %></span>
	<% } ) %>
</script>

<!-- Knockout -->
<div id="koapp">
	<h3>KO</h3>	
  <span data-bind="foreach: items">
  	<span data-bind="text: $data"></span>
  </span>
</div>

<!-- Ember -->
<div id="emapp">
	<h3>Ember</h3>	
  <script type="text/x-handlebars">
    <span>{{#each EMAPP.items}}<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>

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

// KO
var ko_items = ko.observableArray([]);
var ko_viewmodel = {items: ko_items};

ko.applyBindings(ko_viewmodel, document.getElementById('koapp'));

window.KO = {
  clear: function() {
    ko_items.splice(0);
  },
  push: function(data) {
    ko_items.push(data);
  }
}

//Ember
window.EMAPP = Ember.Application.create({
  rootElement: $('#emapp')
});
EMAPP.items = Ember.A();

window.EM = {
  clear: function() {
    EMAPP.items.clear();
  },
  push: function(item) {
    EMAPP.items.pushObject(item);
  }
}

//CanJS
var can_items = new can.Observe.List([]);
$('#canapp')
  .append(can.view('canEJS', {items: can_items}));
  
window.CAN = {
	clear: function () {
		can_items.splice(0);
	},
	push: function (item) {
		can_items.push(item);
	}
}
</script>
	
    

Preparation code output

<!-- Jquery --> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.1.3/angular.min.js"> </script> <script src="http://knockoutjs.com/downloads/knockout-2.2.1.js"> </script> <script src="https://raw.github.com/wycats/handlebars.js/1.0.0-rc.3/dist/handlebars.js"></script> <script src="https://raw.github.com/emberjs/ember.js/release-builds/ember-1.0.0-rc.2.js"> </script> <script src="http://canjs.us/release/1.1.5/can.jquery.js"></script> <!-- CanJS --> <div id="canapp"> <h3>Can</h3> </div> <script type="text/ejs" id="canEJS"> <% list(items, function(item) { %> <span><%= item %></span> <% } ) %> </script> <!-- Knockout --> <div id="koapp"> <h3>KO</h3> <span data-bind="foreach: items"> <span data-bind="text: $data"></span> </span> </div> <!-- Ember --> <div id="emapp"> <h3>Ember</h3> <script type="text/x-handlebars"> <span>{{#each EMAPP.items}}<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> <script> // Angular angular.module('ANGAPP', []) .controller('Ctrl', function($scope) { $scope.items = []; window.ANG = { clear: function() { $scope.items.splice(0); $scope.$digest(); }, push: function(item) { $scope.items.push(item); $scope.$digest(); } }; }); // KO var ko_items = ko.observableArray([]); var ko_viewmodel = {items: ko_items}; ko.applyBindings(ko_viewmodel, document.getElementById('koapp')); window.KO = { clear: function() { ko_items.splice(0); }, push: function(data) { ko_items.push(data); } } //Ember window.EMAPP = Ember.Application.create({ rootElement: $('#emapp') }); EMAPP.items = Ember.A(); window.EM = { clear: function() { EMAPP.items.clear(); }, push: function(item) { EMAPP.items.pushObject(item); } } //CanJS var can_items = new can.Observe.List([]); $('#canapp') .append(can.view('canEJS', {items: can_items})); window.CAN = { clear: function () { can_items.splice(0); }, push: function (item) { can_items.push(item); } } </script>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Angular
ANG.clear();
for (var i = 0; i < 50; i++) {
	ANG.push(i);
}
pending…
Can
CAN.clear();
for (var i = 0; i < 50; i++) {
  CAN.push(i);
}
pending…
Knockout
KO.clear();
for (var i = 0; i < 50; i++) {
  KO.push(i);
}
pending…
Ember
EM.clear();
for (var i = 0; i < 50; i++) {
  EM.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.

0 Comments

Can

KO

Ember

Angular

{{item}}