Angular VS Knockout VS Ember VS React

JavaScript performance comparison

Revision 416 of this test case created by Added framework versions; 10/100 iterations; organized code

Preparation code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<!-- Jquery -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.1.0/knockout-min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.3.0/handlebars.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ember.js/1.5.1/ember.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.10.0/react.min.js"></script>


<!-- Angular (using `track by $index` syntax introduced in v1.2) -->
<div ng-app="ngApp">
  Angular:
  <span ng-controller="Ctrl" id="angList" class="hideoverflow"><span ng-repeat="item in data track by $index">{{::item}}</span></span>
</div>


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

<!-- Ember -->

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


<!-- React -->
<div id="react">
  React: <span id="reactMountNode" class="hideoverflow"></span>
</div>


<script>
/* ANGULAR */
angular.module('ngApp',[]).controller('Ctrl', function($scope) {
  $scope.data = [];
});

$(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.$digest();
    };
  });
});



/* KNOCKOUT */
var KOData = ko.observableArray();
var KOviewmodel = {
  data: KOData
};
ko.applyBindings(KOviewmodel, document.getElementById('koapp'));
window.KOclear = function() {
  KOData.splice(0, KOData().length);
};
window.KOpush = function(data) {
  KOData.push(data);
};



/* EMBER */
var ENV = {
  EXTEND_PROTOTYPES: false
};
EMapp = Ember.Application.create({
  rootElement: '#emapp'
});
EMapp.data = Ember.A();

window.EMclear = function() {
  EMapp.data.clear();
};
window.EMpush = function(data) {
  EMapp.data.pushObject(data);
};



/* REACT */
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: i
      }, this.state.data[i]));
    }
    return React.DOM.span(null, res);
  }
});
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
  });
}
</script>

<style>
.hideoverflow {
  display: block;
  overflow: hidden;
  height: 30px;
}
</style>
      
<script>
Benchmark.prototype.setup = function() {
  var LOOPS = 10;

};
</script>

Preparation code output

<!-- Jquery --> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0/angular.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.1.0/knockout-min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.3.0/handlebars.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/ember.js/1.5.1/ember.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.10.0/react.min.js"></script> <!-- Angular (using `track by $index` syntax introduced in v1.2) --> <div ng-app="ngApp"> Angular: <span ng-controller="Ctrl" id="angList" class="hideoverflow"><span ng-repeat="item in data track by $index">{{::item}}</span></span> </div> <!-- Knockout --> <div id="koapp"> Knockout: <span data-bind="foreach: data" class="hideoverflow"><span data-bind="text: $data"></span></span> </div> <!-- Ember --> <div id="emapp"></div> <script type="text/x-handlebars"> Ember: <span class="hideoverflow"> {{#each EMapp.data}}<span>{{this}}</span>{{/each}} </span> </script> <!-- React --> <div id="react"> React: <span id="reactMountNode" class="hideoverflow"></span> </div> <script> /* ANGULAR */ angular.module('ngApp',[]).controller('Ctrl', function($scope) { $scope.data = []; }); $(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.$digest(); }; }); }); /* KNOCKOUT */ var KOData = ko.observableArray(); var KOviewmodel = { data: KOData }; ko.applyBindings(KOviewmodel, document.getElementById('koapp')); window.KOclear = function() { KOData.splice(0, KOData().length); }; window.KOpush = function(data) { KOData.push(data); }; /* EMBER */ var ENV = { EXTEND_PROTOTYPES: false }; EMapp = Ember.Application.create({ rootElement: '#emapp' }); EMapp.data = Ember.A(); window.EMclear = function() { EMapp.data.clear(); }; window.EMpush = function(data) { EMapp.data.pushObject(data); }; /* REACT */ 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: i }, this.state.data[i])); } return React.DOM.span(null, res); } }); 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 }); } </script> <style> .hideoverflow { display: block; overflow: hidden; height: 30px; } </style>

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
10 x Angular 1.3
ANGclear();
for (var i = 0; i < LOOPS; i++)
  ANGpush(i);
pending…
10 x Knockout 3.1
KOclear();
for (var i = 0; i < LOOPS; i++)
  KOpush(i);
pending…
10 x Ember 1.5
EMclear();
for (var i = 0; i < LOOPS; i++)
  EMpush(i);
pending…
10 x React 0.1
RClear();
for (var i = 0; i < LOOPS; i++)
  RPush(i);
pending…
100 x Angular 1.3
ANGclear();
for (var i = 0; i < LOOPS * 10; i++)
  ANGpush(i);
pending…
100 x Knockout 3.1
KOclear();
for (var i = 0; i < LOOPS * 10; i++)
  KOpush(i);
pending…
100 x Ember 1.5
EMclear();
for (var i = 0; i < LOOPS * 10; i++)
  EMpush(i);
pending…
100 x React 0.1
RClear();
for (var i = 0; i < LOOPS * 10; i++)
  RPush(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.

1 Comment

Renkai commented :

Thanks for putting togther this helpful test!

Angular: {{::item}}
Knockout:
React: