exoskeleton vs backbone events (v23)

Revision 23 of this benchmark created on


Preparation HTML

<script src='//cdnjs.cloudflare.com/ajax/libs/lodash.js/2.2.0/lodash.underscore.js'></script>
<script src='//cdnjs.cloudflare.com/ajax/libs/backbone.js/1.2.1/backbone-min.js'></script>
<script>var bbEvents = Backbone.Events;</script>
<script>var extend = _.extend; window._ = null;</script>
<script src="https://github.com/paulmillr/exoskeleton/releases/download/0.6.3/exoskeleton.js"></script>
<script>var exosEvents = Exoskeleton.Events;</script>
<script>
var EventEmitter = {
  on: function(ev, handler) {
    var events = this._events;

    (events[ev] || (events[ev] = [])).push(handler);
  },
  removeListener: function(ev, handler) {
    var array = this._events[ev];

    array && array.splice(array.indexOf(handler), 1);
  },
  emit: function(ev) {
    if (!this._events) return this

    var args = [].slice.call(arguments, 1),
        array = this._events[ev] || [];
    
    this._triggerEvents(array, args);
  },
  once: function(ev, handler) {
    this.on(ev, remover);

    function remover() {
      handler.apply(this, arguments);
      this.removeListener(ev, remover);
    }
  },
  off: function() {
    this._events = {};
  },
  _triggerEvents: function(evs, args) {
    var ev, i = -1, l = evs.length, a1 = args[0], a2 = args[1], a3 = args[2];

    switch (args.length) {
      case 0: while (++i < l) (ev = evs[i]).callback.call(ev.ctx); return;
      case 1: while (++i < l) (ev = evs[i]).callback.call(ev.ctx, a1); return;
      case 2: while (++i < l) (ev = evs[i]).callback.call(ev.ctx, a1, a2); return;
      case 3: while (++i < l) (ev = evs[i]).callback.call(ev.ctx, a1, a2, a3); return;
      default: while (++i < l) (ev = evs[i]).callback.apply(ev.ctx, args); return;
    }
  },
  constructor: function() {
    this._events = {};
    return this;
  }
};
var EE = EventEmitter.constructor();
</script>

Setup

var numEvents = 3;
    var numListeners = 100;
    var bb = extend({x:0}, bbEvents);
    var exos = extend({x:0}, exosEvents);
    var ee = extend({x:0}, EE);
    [bb, exos, ee].forEach(function(obj) {
      obj.on('event1', function() { obj.x++; });
      obj.on('event2', function() { obj.x++; });
      obj.off();
    });

Test runner

Ready to run.

Testing in
TestOps/sec
Exoskeleton
for (var i = 0; i < 100; i++) exos.trigger('event' + i, 1, 2, 3);
ready
Backbone
for (var i = 0; i < 100; i++) bb.trigger('event' + i, 1, 2, 3);
ready
EE
for (var i = 0; i < 100; i++) ee.emit('event' + i, 1, 2, 3);
ready

Revisions

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