Mithril React Ember Knockout Angular (v25)

Revision 25 of this benchmark created on


Preparation HTML

<!-- Jquery -->
<script src="http://cdn.jsdelivr.net/jquery/1.11.2/jquery.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.15/angular.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/knockout/3.3.0/knockout-min.js"></script>
<script src="http://builds.emberjs.com/canary/ember-template-compiler.js"></script>
<script src="http://builds.emberjs.com/canary/ember.prod.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/react/0.13.2/react-with-addons.min.js"></script>
<script src="https://cdn.rawgit.com/lhorie/mithril.js/next/mithril.min.js"></script>
<!-- Angular -->
<div ng-app="jsperf">
  Angular:
  <span ng-controller="Ctrl" id="angList"><span ng-repeat="item in data track by $index ">{{item}}</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>
<script>
var r = function() {
  return Math.trunc(Math.random() * 1000);
};

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

angular.module('jsperf', [])
  .controller('Ctrl', Ctrl);

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

var ENV = {
  EXTEND_PROTOTYPES: false
};

var MithrilData = [];
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.$digest();
    };
    window.ANGpush = function(data) {
      ang_scope.data.push(data);
      ang_scope.$digest();
    };
  });

  ko.applyBindings(KOviewmodel, document.getElementById('koapp'));
  window.KOclear = function() {
    KOData.removeAll();
  };
  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);
  };

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

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

  var PerfTest = React.createClass({
    displayName: 'PerfTest',
    getInitialState: function() {
      return { data: [] };
    },
    render: function() {
      return React.createElement('span', null, this.state.data.map(function(data,i) {
        return React.createElement('span', {key: i}, data);
      }));
    }
  });

  var reactComp = React.render(React.createElement(PerfTest, null), document.getElementById('reactMountNode'));

  window.RClear = function() {
    reactComp.setState({
      data: []
    });
  };

  window.RPush = function(data) {
    reactComp.state.data.push(data);
    reactComp.forceUpdate();
  };

});
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Mithril
Mclear();
for (var i = 0; i < 100; i++)
  Mpush(r());
ready
React
RClear();
for (var i = 0; i < 100; i++)
  RPush(r());
ready
Angular
ANGclear();
for (var i = 0; i < 100; i++)
  ANGpush(r());
ready
Knockout
KOclear();
for (var i = 0; i < 100; i++)
  KOpush(r());
ready
Ember
EMclear();
for (var i = 0; i < 100; i++)
  EMpush(r());
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.