Angular vs Knockout vs React vs Matreshka (100 items)

JavaScript performance comparison

Revision 22 of this test case created by Andrey Gubanov

Preparation code

<!-- Jquery -->
<script src="https://cdn.jsdelivr.net/jquery/2.1.0/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/angularjs/1.2.15/angular.min.js"></script>
<script src="https://cdn.jsdelivr.net/knockout/3.1.0/knockout.js"></script>
<script src="https://cdn.jsdelivr.net/react/0.10.0/react-with-addons.js"></script>
<script src="http://coding.farm/js/matreshka.min.js"></script>


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


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


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


<!-- Matreshka -->
<div id="matreshka">
  Matreshka: <span id="matreshkaMountNode"></span>
</div>


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

var KOData = ko.observableArray();
var KOviewmodel = {data: KOData};

var ENV = {EXTEND_PROTOTYPES: false};

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: 'test' + i }, this.state.data[i]));
    }
    return React.DOM.span(null, res);
  }
});


var MatreshkaModel = MK.Class({
	'extends': MK.Object,
	constructor: function(data) {
		this.set(data);
	},
	onRender: function(evt) {
		this.bindNode('value', evt.node, {
			setValue: function(v) {
				this.innerHTML = v;
			}
		});
	}
});

var matreshkaApp = new MK.Class({
	'extends': MK.Array,
	Model: MatreshkaModel,
	itemRenderer: '<span>',
	constructor: function() {
		this.bindNode( 'sandbox', '#matreshkaMountNode' );
	}
});


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

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


  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});
  }


  window.MKpush = function( value ) {
  	matreshkaApp.push({ value: value });
  };

  window.MKclear = function() {
  	matreshkaApp.recreate();
  };
});
</script>

    

Preparation code output

<!-- Jquery --> <!-- Angular --> <div ng-app> Angular: <span ng-controller="Ctrl" id="angList"><span ng-repeat="item in data">{{item}}</span></span> </div> <!-- Knockout --> <div id="koapp"> Knockout: <span data-bind="foreach: data"><span data-bind="text: $data"></span></span> </div> <!-- React --> <div id="react"> React: <span id="reactMountNode"></span> </div> <!-- Matreshka --> <div id="matreshka"> Matreshka: <span id="matreshkaMountNode"></span> </div>

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 100
ANGclear();
for (var i = 0; i < 100; i++)
  ANGpush("ngitem");
pending…
Knockout 100
KOclear();
for (var i = 0; i < 100; i++)
  KOpush("koitem");
pending…
React 100
RClear();
for (var i = 0; i < 100; i++)
  RPush("ritem");
pending…
Matreshka 100
MKclear();
for (var i = 0; i < 100; i++)
  MKpush("mkitem");
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

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