PubSubJS vs. jQuery custom events

JavaScript performance comparison

Revision 20 of this test case created


An attempt at showing that PubSubJS is faster than using jQuery custom evens for publish/subscribe style messaging.

It's certainly not as rich in features, and I am happy with that.

Introducing PubSubJS

Preparation code

<script src="//"></script>
<script src=""></script>
  var callback1 = function() {};
  var callback2 = function() {};
  var callback3 = function() {};
  var payload = {
   somekey: 'some value'
  var j;
  var topics = {};
  // let's use jQuery.ready to make sure that the DOM is ready,
  // before trying to work with it
  jQuery(function() {
   // we'll use the body element to exchange messages for jQuery
   // if using deeper nested elements, jQuery will be slower, as custom events bubble
   j = $({});
   // subscribe our callback1 function to the custom event for jQuery, only once
   j.on('my-event', callback1);
   // subscribe our callback2 function to the message for PubSub
   PubSub.subscribe('my-event', callback2);

   // subscribe our callback3 function to the callbacks for jQuery.

   topics["my-event"] = $.Callbacks();


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 - trigger - custom event
j.trigger('my-event', payload);
PubSub - publish - asyncronous
PubSub.publish('my-event', payload);
PubSub - publish - syncronous
PubSub.publish('my-event', payload, true);
jQuery - fire - $.Callbacks

Compare results of other browsers


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:


Add a comment