Events vs Events2

JavaScript performance comparison

Revision 17 of this test case created

Preparation code

<script src='//cdnjs.cloudflare.com/ajax/libs/jquery/1.8.3/jquery.min.js'></script>
<script src='//underscorejs.org/underscore.js'></script>
<script src='//cdnjs.cloudflare.com/ajax/libs/backbone.js/0.9.2/backbone-min.js'></script>
<script>var oldEvents = Backbone.Events;</script>
<script src='//cdnjs.cloudflare.com/ajax/libs/backbone.js/0.5.3/backbone-min.js'></script>
<script>var olderEvents = Backbone.Events;</script>
<script src='//backbonejs.org/backbone.js'></script>
<script>var masterEvents = Backbone.Events;</script>
<script src='//cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.0.rc.1/handlebars.min.js'></script>
<script src='//cdnjs.cloudflare.com/ajax/libs/ember.js/1.0.0-pre.2/ember-1.0.0-pre.2.min.js'></script>
<script>var emberEvents = Ember.Object.create(Ember.Evented);</script>
<script>
Benchmark.prototype.setup = function() {
    old = _.extend({}, oldEvents);
    older = _.extend({}, olderEvents);
    master = _.extend({}, masterEvents);
    jquery = $({});
   
    numEvents = 3;
    numListeners = 100;
   
    _.times(numEvents, function(event) {
      _.times(numListeners, function() {
        older.bind("event" + event, function(){});
        old.on("event" + event, function(){});
        jquery.on("event" + event, function(){});
        master.on("event" + event, function(){});
        emberEvents.on("event" + event, function(){});
      });
    });
};
</script>

Preparation code output

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
jQuery 1.8.3
for (var i = 0; i < numEvents; i++) {
  jquery.triggerHandler('event' + i, 1, 2);
}
pending…
Backbone 0.5.3
for (var i = 0; i < numEvents; i++) {
  older.trigger('event' + i, 1, 2);
}
pending…
Backbone 0.9.2
for (var i = 0; i < numEvents; i++) {
  old.trigger('event' + i, 1, 2);
}
pending…
Backbone 0.9.9
for (var i = 0; i < numEvents; i++) {
  master.trigger('event' + i, 1, 2);
}
pending…
Ember
for (var i = 0; i < numEvents; i++) {
  emberEvents.trigger('event' + i, 1, 2);
}
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