Events vs Events2

JavaScript performance comparison

Revision 14 of this test case created

Info

Adding Knockout.js for reference.

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='http://knockoutjs.com/downloads/knockout-2.2.0.js'></script>
<script>
Benchmark.prototype.setup = function() {
    old = _.extend({}, oldEvents);
    older = _.extend({}, olderEvents);
    master = _.extend({}, masterEvents);
    jquery = $({});
    knockout= new ko.subscribable();
   
    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(){});
        knockout.subscribe(function(){},null,"event" + event);
      });
    });
};
</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.trigger('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…
Knockout v2.2.0
for (var i = 0; i < numEvents; i++) {
 knockout.notifySubscribers(i, 'event' + i);
}
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