A Circle Benchmark: Backbone vs. Ember vs. React vs. Ractive vs. Vue vs. Basis.js

by garnwraly

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.10.1/lodash.min.js"></script>
<script src="http://backbonejs.org/backbone-min.js"></script>
<script src="http://builds.handlebarsjs.com.s3.amazonaws.com/handlebars-v1.3.0.js"></script>
<script src="https://rawgithub.com/ebryn/0bbe6639da1166bef3ee/raw/c5f715bbee4200d328065fdb34b0bb49f2d748cf/ember-htmlbars-dont-use-me-anywhere-else.prod.js"></script>
<script src="http://react.zpao.com/builds/master/latest/react.min.js"></script>
<script src="http://vuejs.org/js/vue.min.js"></script>
<script src="http://cdn.ractivejs.org/latest/ractive.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/basis.js/1.2.1/basis.min.js"></script>
<script src="https://cdn.rawgit.com/Raynos/mercury/6e260f4cde227683552fd9ca8c3c242be8d5b07c/dist/mercury.js"></script>

<p>
    This is a fork of <a href="http://jsfiddle.net/jashkenas/CGSd5/" target="_top">jashkenas's Ember/Backbone</a> benchmark to include Vue.js. Note that this is just a simple benchmark: you wouldn't be doing this in an actual app.
</p>

<p>The original fork was clocking the loops synchronously which was not accurate. This fork fixes that, and also gives a 300ms pause before clock starts to offset initialization time. It uses performance.now instead of new Date approach for more accurate time and fix results after every 500 iteration.</p>

<button onclick="runBackbone()">Animate with Backbone</button>
<button onclick="runEmber()">Animate with Ember+HTMLBars</button>
<button onclick="runReact()">Animate with React</button>
<button onclick="runRactive()">Animate with Ractive</button>
<button onclick="runVue()">Animate with Vue</button>
<button onclick="runMercury()">Animate with Mercury</button>
<button onclick="runBasis()">Animate with Basis.js</button>
<button onclick="runBasisTemplate()">Animate with Basis.js (template)</button>
<button onclick="runRawdog()">Animate with nothing</button>


<p id="timing">&nbsp;</p>
<p...

CSS

p {
  font: 12px/16px Arial;
  margin: 10px 10px 15px;    
}

button {
  font: bold 14px/14px Arial;  
  margin-left: 10px;
}

#grid {
  margin: 10px;
}

#timing {
  clear: both;
  padding-top: 10px;
}

.box-view {
  width: 20px; height: 20px;
  float: left;
  position: relative;
  margin: 8px;    
}

.box {
  border-radius: 100px;
  width: 20px; height: 10px;
  padding: 5px 0;
  color: #fff;
  font: 10px/10px Arial;
  text-align: center;
  position: absolute;
}

JavaScript

// Change N to change the number of drawn circles.

var N = 100;

// The Backbone implementation:
(function(){

var Box = Backbone.Model.extend({

    defaults: {
        top: 0,
        left: 0,
        color: 0,
        content: 0
    },

    initialize: function() {
        this.count = 0;
    },

    tick: function() {
        var count = this.count += 1;
        this.set({
            top: Math.sin(count / 10) * 10,
            left: Math.cos(count / 10) * 10,
            color: (count) % 255,
            content: count % 100
        });
    }

});


var BoxView = Backbone.View.extend({

    className: 'box-view',

    template: _.template($('#underscore-template').html()),

    initialize: function() {
        this.model.bind('change', this.render, this);
    },

    render: function() {
        this.$el.html(this.template(this.model.attributes));
        return this;
    }

});

var boxes;

var backboneInit = function() {
    boxes = _.map(_.range(N), function(i) {
        var box = new Box({number: i});
        var view = new BoxView({model: box});
        $('#grid').append(view.render().el);
        return box;
    });
};

var backboneAnimate = function() {
    for (var i = 0, l = boxes.length; i < l; i++) {
      boxes[i].tick();
    }
};

window.runBackbone = function() {
    reset();
    backboneInit();
    setTimeout(function () {
          startClock();
          benchmarkLoop(backboneAnimate);
    }, 300);
};

})();

// The Ember implementation:
(function(){

var Box = Ember.Object.extend({

    top: 0,
    left: 0,
    content: 0,
    count: 0,

    tick: function() {
        var count = this.get('count') + 1;
        this.set('count', count);
        this.set('top', Math.sin(count / 10) * 10);
        this.set('left', Math.cos(count / 10) * 10);
        this.set('color', count % 255);
        this.set('content', count % 100);
        this.set('style', this.computeStyle());
    },

    computeStyle: function() {
        return 'top: ' +...