Events vs Events2

JavaScript performance comparison

Revision 35 of this test case created by stefan and last updated

Preparation code

<script src='//cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js'></script>
<script src="//rawgithub.com/wycats/handlebars.js/1.0.0-rc.3/dist/handlebars.runtime.js"></script>
<script src='//cdnjs.cloudflare.com/ajax/libs/lodash.js/1.2.1/lodash.underscore.js'></script>
<script src='//cdnjs.cloudflare.com/ajax/libs/backbone.js/1.0.0/backbone-min.js'></script>
<script>
  var backboneEvents = Backbone.Events;
</script>
<script src="//builds.emberjs.com.s3.amazonaws.com/ember-1.0.0-rc.3.min.js"></script>
<script>
  var emberEvents = Ember.Object.extend(Ember.Evented);
</script>
<script>
Benchmark.prototype.setup = function() {
    var backboneObject = _.extend({x:0}, backboneEvents);
    var emberObject = emberEvents.create({x:0});
    var jqueryObject = $({x:0});
   
    var numEvents = 3;
    var numListeners = 100;
    var objs = [backboneObject, emberObject, jqueryObject];
   
    _.times(numEvents, function(n) {
      _.times(numListeners, function() {
        _.each(objs, function(obj) {
          obj.on('event' + n, function() { obj.x++; });
        });
      });
    });
};
</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
Backbone
for (var i = 0; i < numEvents; i++) {
  backboneObject.trigger('event' + i, 1, 2, 3);
}
pending…
Ember
for (var i = 0; i < numEvents; i++) {
  emberObject.trigger('event' + i, 1, 2, 3);
}
pending…
jQuery
for (var i = 0; i < numEvents; i++) {
  jqueryObject.triggerHandler('event' + i, [1, 2, 3]);
}
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