Events vs Events2

JavaScript performance comparison

Revision 10 of this test case created by Romain Beauxis

Preparation code

<script src='http://code.jquery.com/jquery-1.8.3.js'></script>
<script src='https://raw.github.com/documentcloud/underscore/master/underscore.js'></script>
<script src='https://raw.github.com/documentcloud/backbone/0.9.2/backbone.js'></script>
<script>var oldEvents = Backbone.Events;</script>
<script src='https://raw.github.com/documentcloud/backbone/0.5.3/backbone.js'></script>
<script>var olderEvents = Backbone.Events;</script>
<script src='https://raw.github.com/documentcloud/backbone/master/backbone.js'></script>
<script>var masterEvents = Backbone.Events;</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(){});
      });
    });
   
};
</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, 3, 4);
}
pending…
Backbone 0.5.3
for (var i = 0; i < numEvents; i++) {
  older.trigger('event' + i, 1, 2, 3, 4);
}
pending…
Backbone 0.9.2
for (var i = 0; i < numEvents; i++) {
  old.trigger('event' + i, 1, 2, 3, 4);
}
pending…
Backbone 0.9.9
for (var i = 0; i < numEvents; i++) {
  master.trigger('event' + i, 1, 2, 3 ,4);
}
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