Events vs Events2

JavaScript performance comparison

Test case created

Preparation code

<script src='https://raw.github.com/documentcloud/underscore/master/underscore.js'></script>
<script src='https://raw.github.com/caseywebdev/backbone/events/backbone.js'></script>
<script>var one = Backbone.Events;</script>
<script src='https://raw.github.com/caseywebdev/backbone/events2/backbone.js'></script>
<script>var two = Backbone.Events;</script>
<script>
Benchmark.prototype.setup = function() {
    var obj1 = _.extend({}, one);
    var obj2 = _.extend({}, two);
    var i, l = 20;
};
</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
on/off (many events) - one
for (i = 0; i < l; ++i) {
  obj1.on('event', function () {});
  obj1.on('event2', function () {});
  obj1.on('event3', function () {});
}
obj1.off();
pending…
on/off (many events) - two
for (i = 0; i < l; ++i) {
  obj2.on('event', function () {});
  obj2.on('event2', function () {});
  obj2.on('event3', function () {});
}
obj2.off();
pending…
trigger (many events) - one
for (i = 0; i < l; ++i) {
  obj1.on('event'+i, function () {});
}
for (i = 0; i < l; ++i) {
  obj1.trigger('event'+i);
}
pending…
trigger (many events) - two
for (i = 0; i < l; ++i) {
  obj2.on('event'+i, function () {});
}
for (i = 0; i < l; ++i) {
  obj2.trigger('event'+i);
}
pending…
on/trigger/off (3 events) - one
obj1.on('event', function () {});
obj1.on('event2', function () {});
obj1.on('event3', function () {});
obj1.trigger('event', function () {});
obj1.trigger('event2', function () {});
obj1.trigger('event3', function () {});
obj1.off();
pending…
on/trigger/off (3 events) - two
obj2.on('event', function () {});
obj2.on('event2', function () {});
obj2.on('event3', function () {});
obj2.trigger('event', function () {});
obj2.trigger('event2', function () {});
obj2.trigger('event3', function () {});
obj2.off();
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