Events vs Events2

JavaScript performance comparison

Revision 24 of this test case created

Preparation code

<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() {
    var old = _.extend({}, oldEvents);
    var older = _.extend({}, olderEvents);
    var master = _.extend({}, masterEvents);
   
    var numEvents = 3;
    var numListeners = 100;
   
    _.times(numEvents, function(event) {
      _.times(numListeners, function() {
        old.on("event" + event, function(){});
        older.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
0.5.3
for (var i = 0; i < numEvents; i++) {
  older.trigger('event' + i);
}
pending…
0.9.2
for (var i = 0; i < numEvents; i++) {
  old.trigger('event' + i);
}
pending…
master
for (var i = 0; i < numEvents; i++) {
  master.trigger('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