A Comparison of JS Publish/Subscribe Approaches (v114)

Revision 114 of this benchmark created on


Description

A Comparison of JS Publish/Subscribe Approaches

More info: publish/subscribe on Wikipedia.

Compared:

Preparation HTML

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<script src="https://raw.github.com/mroderick/PubSubJS/master/src/pubsub.js">
</script>
<script src="https://raw.github.com/phiggins42/bloody-jquery-plugins/master/pubsub.js">
</script>
<script src="https://raw.github.com/phiggins42/bloody-jquery-plugins/55e41df9bf08f42378bb08b93efcb28555b61aeb/pubsub.js">
</script>
<script src="https://raw.github.com/gist/1695338/736bcf94f9226d975fce3ad4f2bc08ccbf176bad/pubsub.js">
</script>
<script src="https://raw.github.com/appendto/amplify/master/core/amplify.core.js">
</script>
<script src="https://raw.github.com/maccman/spine/master/lib/spine.js">
</script>
<script>
var callback = function() {
//console.log('callback');
   //deferred.resolve();
    };
var payload = {
  somekey: 'some value'
};
var body;
var handle;

jQuery(function() {
  $(window).bind('my-event', callback);
  PubSub.subscribe('my-event', callback)
  $.subscribe('my-event', callback);
  handle = Events.subscribe('my-event', callback);
  App.subscribe('my-event', callback);
  //amplify.subscribe('my-event', callback);
  Spine.bind('my-event', callback);
});
</script>

Setup

var callback = function() {
    //console.log('callback');
       //deferred.resolve();
        };
    var payload = {
      somekey: 'some value'
    };
    var body;
    var handle;
    
    jQuery(function() {
      $(window).bind('my-event', callback);
      PubSub.subscribe('my-event', callback)
      $.subscribe('my-event', callback);
      handle = Events.subscribe('my-event', callback);
      App.subscribe('my-event', callback);
      //amplify.subscribe('my-event', callback);
      Spine.bind('my-event', callback);
    });

Teardown


    //$(window).unbind('my-event');
    //PubSub.unsubscribe('my-event')
    //$.unsubscribe('my-event');
    //Events.unsubscribe(handle);
    //App.unsubscribe('my-event');
    //amplify.unsubscribe('my-event');
    //Spine.unbind('my-event');
  

Test runner

Ready to run.

Testing in
TestOps/sec
jQuery Events
// async test
$(window).bind('my-event', function(){
  deferred.resolve();
});
$(window).trigger('my-event');
$(window).unbind('my-event');
 
ready
PubSubJS
PubSub.publish('my-event', payload);
ready
jQuery PubSub plugin
$.publish('my-event', [payload]);
ready
Pure JS PubSub
Events.publish('my-event', [payload]);
ready
Darcy Clarke
App.publish('my-event', [payload]);
ready
Amplify Pub/Sub
//amplify.publish('my-event', payload);
ready
Spine Events
Spine.trigger('my-event', payload);
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.