Angular VS Knockout VS Ember VS React VS Mithril

JavaScript performance comparison

Revision 345 of this test case created

Info

This is a simple rendering speed test between the most popular libraries/frameworks. I added in Mithril because it's a newcomer with some promise.

Preparation code

<!-- Jquery -->
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.16/angular.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/knockout/3.1.0/knockout-min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.3.0/handlebars.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/ember.js/1.5.1/ember.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/react/0.10.0/react.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/mithril/0.1.12/mithril.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/vue/0.10.5/vue.min.js"></script>

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


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

<!-- Ember -->

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


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


<!-- Mithril -->
<div id="mithrilapp">
  Mithril: <span id="mithrilMountNode"></span>
</div>


<!-- Vuejs -->
<div id="vuejs">
        Vuejs: <span id="vuejsMountNode"><span v-repeat="item: data">{{ item }}</span></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() {
 
    return (
      React.DOM.span(null,
        this.state.data.map(function(result) {
          return React.DOM.span( {key:result.id}, result.text);
        })
      )
    );
   
  }
});

var MithrilData = new Array();
var mithapp = {
  controller: function() {
    this.data = MithrilData;
  },
  view: function(ctrl) {
    return m("span", [ctrl.data.map(function(datum) { return m('span', datum); })]);
  }
}

$(document).ready(function() {
  angular.element(document).ready(function() {
    var ang_scope = $('#angList').scope();

    window.ANGclear = function(){
      ang_scope.data = [];
      ang_scope.$apply();
    };
    window.ANGpush = function(data){
      ang_scope.data.push(data);
      ang_scope.$apply();
    };
  });

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



  EMapp = Ember.Application.create({
    rootElement: '#emapp'
  });
  EMapp.data = Ember.A();

  window.EMclear = function () {
    EMapp.data.clear();
  };
  window.EMpush = function (data) {
    EMapp.data.pushObject(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});
  }

  m.module(document.getElementById("mithrilMountNode"), mithapp);
  window.Mclear = function() {
    m.startComputation();
    MithrilData.splice(0);
    m.endComputation();
  };

  window.Mpush = function(data) {
    m.startComputation();
    MithrilData.push(data);
    m.endComputation();
  }
 

  var vueInstance = new Vue({
          el: '#vuejsMountNode',
          data: {
                  data: []
          }
  });
 
  window.VueClear = function(){
          vueInstance.data = []
  };

  window.VuePush = function(data){
                vueInstance.data.push(data);
  };
 

 
});
</script>
 

Preparation code output

Angular: {{item.name}}
Knockout:
React:
Mithril:
Vuejs: {{ item }}

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
ANGclear();
for (var i = 0; i < 100; i++)
  ANGpush({id: i, name: "ngitem"});
pending…
Knockout
KOclear();
for (var i = 0; i < 100; i++)
  KOpush("koitem");
pending…
React
RClear();
for (var i = 0; i < 100; i++)
  RPush("ritem");
pending…
Mithril
Mclear();
for (var i = 0; i < 100; i++)
  Mpush("mitem");
pending…
vuejs
VueClear();
for (var i = 0; i < 100; i++)
  VuePush("vitem");
pending…
Ember
EMclear();
for (var i = 0; i < 100; i++)
  EMpush("emitem");
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