A Comparison of JS Publish/Subscribe Approaches (v144)

Revision 144 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" type="text/javascript">
</script>
<script src="https://rawgithub.com/mroderick/PubSubJS/master/src/pubsub.js" type="text/javascript">
</script>
<script src="https://rawgithub.com/kuwabarahiroshi/bloody-jquery-plugins/master/pubsub.js" type="text/javascript">
</script>
<script src="https://rawgithub.com/phiggins42/bloody-jquery-plugins/55e41df9bf08f42378bb08b93efcb28555b61aeb/pubsub.js" type="text/javascript">
</script>
<script src="https://rawgithub.com/gist/1695338/736bcf94f9226d975fce3ad4f2bc08ccbf176bad/pubsub.js" type="text/javascript">
</script>
<script src="https://rawgithub.com/appendto/amplify/master/lib/amplify.min.js" type="text/javascript">
</script>
<script src="https://rawgithub.com/spine/spine/master/lib/spine.js" type="text/javascript">
</script>
<script src="https://rawgithub.com/richardscarrott/ply/master/src/core.js" type="text/javascript">
</script>
<script src="https://rawgithub.com/BennyC/pubbie/master/build/pubbie.min.js" type="text/javascript">
</script>
<script src="https://rawgithub.com/jrburke/requirejs/master/require.js" type="text/javascript">
</script>
<script type="text/javascript">
window.callback = function () {};
window.payload = {
  somekey: 'some value'
};
var Observer = jQuery({});

jQuery(function() {
  for (var i = 0; i < 5000; i++) {
    Observer.on('my-event-' + i, callback);
    PubSub.subscribe('my-event-' + i, callback);
    jQuery.subscribe('my-event-' + i, callback);
    Events.subscribe('my-event-' + i, callback);
    //App.subscribe('my-event-' + i, callback);
    amplify.subscribe('my-event-' + i, callback);
    Spine.bind('my-event-' + i, callback);
    Ply.core.listen('my-event-' + i, callback);
    pubbie.subscribe('my-event-'+i, callback);
  }
});

</script>

Test runner

Ready to run.

Testing in
TestOps/sec
jQuery Events
Observer.trigger('my-event-3456', payload);
 
ready
PubSubJS
PubSub.publish('my-event-3456', payload);
ready
jQuery PubSub plugin
$.publish('my-event-3456', [payload]);
ready
Pure JS PubSub
Events.publish('my-event-3456', [payload]);
ready
Amplify Pub/Sub
amplify.publish('my-event-3456', payload);
ready
Spine Events
Spine.trigger('my-event-3456', payload);
ready
Ply Notify/Listen
Ply.core.notify('my-event-3456', window, payload);
ready
pubbie
pubbie.publish('my-event-3456', [payload]);
ready

Revisions

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