A Comparison of JS Publish/Subscribe Approaches (v21)

Revision 21 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>

Setup

var callback = function() { };
    var payload = {
      somekey: 'some value'
    };
    var body;
    var handle;
    var topics={};
    
      $(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);
      topics["my-event"] = $.Callbacks();
      topics["my-event"].add(callback);

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
jQuery Callbacks
topics["my-event"].fire(payload);
ready

Revisions

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