Angular VS Knockout VS Ember

JavaScript performance comparison

Revision 41 of this test case created

Info

I saw an unfair comparison between Angular, Knockout, ExtJS, and Backbone, and it made me mad.

This version uses angular 1.2, knockout 2.2.0 and ember-1.0.0-pre.2

Preparation code

<!-- Jquery -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

<script>
  window.run_number_ng = 0;
  window.run_number_ko = 0;
  window.run_number_em = 0;
</script>


<!-- Angular -->
<div ng-app>
  Angular:
  <span ng-controller="Ctrl" id="angList"><span ng-repeat="item in data">{{item}}</span></span>
</div>

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

<script>
  var Ctrl = function($scope){
    $scope.data = [];
  }
 

  angular.element(document).ready(function() {
    var ang_scope = $('#angList').scope();
   
    window.ANGclear = function(){
      ang_scope.data.length = 0;
      ang_scope.$digest();
    };
    window.ANGpush = function(data){
      ang_scope.data.push(data);
      ang_scope.$digest();
    };
  });
</script>


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

<script src="http://cdnjs.cloudflare.com/ajax/libs/knockout/2.2.0/knockout-min.js"></script>

<script>
  var KOData = ko.observableArray();
  var KOviewmodel = {data: KOData};
 
  ko.applyBindings(KOviewmodel, document.getElementById('koapp'));
  var KOclear = function (){
    KOviewmodel.data().length = 0;
    KOviewmodel.data.valueHasMutated();
  };
  var KOpush = function (data){
    KOData.push(data);
  };
</script>



 

Preparation code output

Angular: {{item}}
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
Angular 100
ANGclear();
for (var i = 0; i < 100; i++)
  ANGpush("ngitem"+window.run_number_ng);

window.run_number_ng++;
pending…
Knockout 100
KOclear();
for (var i = 0; i < 100; i++)
  KOpush("koitem"+window.run_number_ko);

window.run_number_ko++;
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:

1 comment

bullgare commented :

If you just remove ang_scope.$digest() from the loop and do it after the loop then angular's performance will increase from 10.67 op/sec to 24.93 on my machine (while knockout's performance is 30.64). I'm sure there can be more improvements. But making $digest() after each change is just not how angular works.

Add a comment